# 这是ADB测试工具主逻辑文件
import sys, os
import re
import shutil
import signal
import time
import tkinter, tkinter.ttk, tkinter.messagebox, tkinter.filedialog
import threading
import getpass, pyperclip, win32api, win32ui,psutil
import public, quickly, screen_record, linux_main, customize_main,log,language_chs,monkey
import traceback
from PIL import Image, ImageTk
from customize_main import AdbShell

username = getpass.getuser()
main_version_path = public.resource_path(os.path.join('version', 'main_version_history.txt'))
# 创建临时文件夹
make_dir = 'C:\\Users\\' + username + '\\Documents\\DA_Tools\\'
# 工具全局监控异常日志
traceback_log = make_dir + 'traceback.log'
# ADB测试工具全部全局变量集
# 全局变量标记-首次打开工具需要添加临时变量
adb_tools_flag = True
# 全局变量标记-首次打开工具需要处理的
playGif_flag = False
# 防止CPU占用率过高，仅执行一次后闲置，避免重复执行
lower_CPU_utility = False
lower_CPU_utility_connect = False
lower_CPU_utility_disconnect = False
# 全局变量标记-设备类型
devices_linux_flag = False
# 全局变量标记-设备检测
adb_service_flag = False
# 全局变量标记-Linux设备初始化检测
linux_Initialize_flag = True
# 全局变量标记-设备UUID
uuid_server_flag = False
# 全局变量标记-获取UUID需要重启时需要处理的标识
uuid_reboot_flag = False
# 全局变量标记-获取UUID时执行处理
uuid_run_flag = False
# 全局变量标记 - 防冲突功能标识
conflict_model_flag = False
# 全局变量标记 - 选择apk路径
apk_path_install_flag = False
# 全局变量标记 - 选择apk路径
apk_install_flag = False
# 点击按钮第一次需要进行处理的标记
first_button_flag = False
tkinter_messagebox_flag = False
# 冲突软件列表
conflict_software_list = ['PhoenixSuit.exe']
version_path = public.resource_path(os.path.join('version/adb_test_version', 'version_history.txt'))
adb_path = public.resource_path(os.path.join('resources', 'adb-tools.zip'))
adb_version_path = public.resource_path(os.path.join('resources', 'Android Debug Bridge version.txt'))
adb_new_version = public.resource_path(os.path.join('resources', 'ADB_upgrade_version.txt'))  # 定义最新ADB版本号
uuid_path = public.resource_path(os.path.join('resources', 'UUID.ini'))
record_state = public.resource_path(os.path.join('temp', 'record_state.txt'))
devices_type_log = public.resource_path(os.path.join('temp', 'devices_type_log.txt'))  # 记录设备类型
my_logo_path = public.resource_path(os.path.join('resources', 'my_logo.gif'))
linux_type_photo = public.resource_path(os.path.join('resources', 'linux_type_instruction.gif'))
linux_sn_path = public.resource_path(os.path.join('resources', 'linux_sn.ini'))
linux_debug_logo_path = public.resource_path(os.path.join('resources', 'debug_logo.png'))
if not os.path.exists(make_dir):
    os.makedirs(make_dir)
# 创建页面文件，记录文件状态
make_dir_s = make_dir + 'adb_test_temp\\'
# 记录个人打印日志（方便看问题）
log_path = make_dir_s + 'log.log'
# adb本地服务文件路径
adb_tools_path = make_dir + 'adb-tools'
# 调试日志
adb_debug_log = make_dir_s + 'debug.log'
# 进入模式记录
adb_model_text = make_dir_s + 'adb_model_log.log'
# 保存gif或非gif图片转换后的目录（方便工具正常读取）
gif_new_save = make_dir_s + 'gif_new_dir\\'
# 保存个人图片路径（转换前）
personal_photo_origin = make_dir_s + 'personal_photo_origin.txt'
# 保存个人图片路径（最后转换的）
personal_photo_path = make_dir_s + 'personal_photo_path.txt'
# gif或非gif图片转换后的路径
gif_new_path = gif_new_save + 'new.gif'
not_gif_new_path = gif_new_save + 'new.png'
gif = public.playGif(gif_new_path)  # 实例化gif动态播放对象
if not os.path.exists(make_dir_s):
    os.makedirs(make_dir_s)
count_path = make_dir_s + 'screenshots_count.txt'
# Linux模式界面按钮状态标志
linux_button_flag = False
linux_button_flag_path = make_dir_s + 'linux_button_flag.log'
# 主程序启动标志
root_state = make_dir_s + 'root_state.txt'
# 截图页面启动标志
screen_page = make_dir_s + 'screen_page_state.txt'
# 安装页面启动标志
install_page = make_dir_s + 'install_page_state.txt'
# 取图页面启动标志
camera_page = make_dir_s + 'camera_page_state.txt'
# 写号工具页面启动标志
write_number_page = make_dir_s + 'linux_write_number_state.txt'
# 一键获取日志页面启动标志
get_log_page = make_dir_s + 'get_log_state.txt'
# 简易ADB - adb-tools检测标志（这个必须是make_dir）
adb_tools_flag = make_dir + 'adb-tools'
# 卸载APK标记
uninstall_flag = True
# 记录页面状态队列
page_state_list = []
# ------------------------------- 录屏功能
# 录屏状态
record_screen_state = make_dir_s + 'record_state.txt'
# 录屏名称
record_name = make_dir_s + 'record_name.txt'
# 录屏时间
record_time_txt = make_dir_s + 'record_time.txt'
# 记录程序位置
exe_path = public.resource_path(os.path.join('temp', 'exe_path.log'))
# 录屏模式
record_model_log = make_dir_s + 'record_model.log'
record_count = make_dir_s + 'record_count.txt'
# 录屏停止处理
record_stop_config = make_dir_s + 'record_stop.ini'
# ------------------------------- 录屏功能
# ADB升级状态
adb_upgrade_flag = make_dir_s + 'adb_state.ini'
# 冲突软件名称记录
conflict_software_path = make_dir_s + 'conflict_software.txt'
# 冲突软件路径记录
conflict_path = make_dir_s + 'conflict_software_path.txt'
# 记录设置环境变量日志
environ_log = make_dir_s + 'environ_log.log'
# 临时保存系统日志
syslog_log = make_dir_s + 'syslog.log'
# 实时保存设备序列号
devices_log = make_dir_s + 'devices.log'
# 记录apk包路径（检测包名）
apk_path_package_log = make_dir_s + 'apk_path_package.log'
# 存储aapt分析apk包信息
apk_aapt_log = make_dir_s + 'apk_aapt_log.log'
# 记录apk包路径（安装apk）
apk_path_log = make_dir_s + 'apk_path.log'
# 记录apk安装信息
apk_install_log = make_dir_s + 'apk_install_log.log'
# 启动前初始化
if not os.path.exists(adb_upgrade_flag):
    with open(adb_upgrade_flag, 'w') as fp:
        fp.write('')
with open(conflict_software_path, 'w') as fp:
    fp.write('')
if not os.path.exists(traceback_log):
    with open(traceback_log, 'w') as fp:
        fp.write('')
# 调用ADB服务开关
adb_server_all_flag = True  # 默认True打开
# 统一修改版本号
adb_version = 'V1.0.3.5'
adb_version_code = 10350
# 统一修改frame的宽高
width = 367
height = 405
# 统一按钮宽度
width_button = 20
# 设置单选按钮跳转时间（默认单位是秒）
radio_waiting_time = 60
main = make_dir + 'main\\'
function_status = main + 'function_status.log'
# 初始化语言对象
languages = language_chs.Language()
languages_all = languages.all_languages()


def adb_tools_log(fun_name):
    # 捕获异常装饰器
    def log(*args, **kwargs):
        try:
            fun_name(*args, **kwargs)
        except Exception:
            traceback.print_exc()
            # 记录异常
            with open(traceback_log,'w') as fp:
                fp.write(str(traceback.format_exc()))
            content = languages_all['exceptions_content']
            tkinter.messagebox.showinfo(languages_all['exceptions_name'],content.format(traceback_log))
            # 强制结束python.exe程序
            # public.execute_cmd('taskkill /F /IM %s ' % 'python.exe /T')
            pid = os.getpid()  # 获取当前程序pid
            pid_name = psutil.Process(pid).name()  # 根据pid获取当前程序名
            # 强制结束当前程序
            public.execute_cmd('taskkill /F /IM %s ' % pid_name + ' /T')
            pid = os.getpid()
            os.kill(pid,signal.SIGINT)
            sys.exit()
    return log


class ADB_Test(object):
    @adb_tools_log
    def adb_root_form(s, root):
        global adb_server_all_flag
        s.root = root
        adb_server_all_flag = True  # 默认True打开ADB服务
        LOGO_path = public.resource_path(os.path.join('icon', 'android.ico'))
        s.root.title(languages_all['adb_test_name'] + ' ' + adb_version + ' ' + languages_all['platform'])
        s.root.iconbitmap(LOGO_path)
        s.root.resizable(0, 0)
        # s.root.attributes("-toolwindow", 2)  # 去掉窗口最大化最小化按钮，只保留关闭
        # s.root.overrideredirect(1)  # 隐藏标题栏 最大化最小化按钮
        # s.root.config(bg=bg)
        # 软件始终置顶
        # s.root.wm_attributes('-topmost', 1)
        # s.root.protocol('WM_DELETE_WINDOW', s.exit)  # 点击Tk窗口关闭时直接调用s.exit，不使用默认关闭
        # 主程序启动标志
        with open(root_state, 'w') as fp:
            fp.write('1')
        fp.close()

        # 先创建主Frame
        s.main_frame_adb_test()
        # 初始化
        s.software_init()
        # 默认显示窗口页面
        # time.sleep(2)  # 某位陈同学觉得点击过快容易触发，因此加延时2秒
        s.quickly_frame()

    @adb_tools_log
    def software_init(s):
        global playGif_flag, adb_tools_flag
        # 每次启动本软件都需要进行初始化

        if adb_tools_flag:  # 表示首次启动本工具才执行，之后无需添加，避免多次重复添加临时变量
            # 添加临时adb-tools环境变量（方便开发者调试，避免出现IndexError、ValueError异常） -- 双重保证系统及工具识别到本地服务
            environ_list = os.environ["PATH"]
            if adb_tools_path not in environ_list: # 避免重复添加导致环境变量导致系统环境变量错乱
                public.temporary_environ(adb_tools_path)
            else:
                print('已设置环境变量，无需重复添加！')
            adb_tools_flag = False

        # 启动ADB服务
        public.execute_cmd('adb start-server')

        # 初始化Linux模式下的特定按钮状态
        init_button_files = [screen_page, install_page, camera_page, write_number_page, get_log_page,public.linux_extra_page()]
        for init_button_file in init_button_files:
            try:
                os.remove(init_button_file)
            except FileNotFoundError:
                pass

        # 检查adb-tools文件里面是否产生多余的tmp文件，有则删除
        try:
            tmp_files = public.get_files(adb_tools_path)
            tmp_files_list = [i for i in tmp_files if i is not None if i.find('tmp') != -1]  # i.find 模糊匹配查询，同时去除空值
            if tmp_files_list:  # 判断tmp文件是否产生，如不产生则不会去删除
                [os.remove(adb_tools_path + '\\' + tmp_file) for tmp_file in tmp_files_list]  # 列表推导式
        except TypeError:
            print('当前文件没有冗余的tmp文件，无需删除！')

        # 创建特定必须的文件
        if not os.path.exists(apk_aapt_log):
            with open(apk_aapt_log, 'w') as fp:
                fp.write('')
            fp.close()
        if playGif_flag:
            public.playGif(gif_new_path)  # 实例化gif动态播放对象

        # 每次启动需要加载的frame
        s.my_logo_label_warning = tkinter.Label(s.root, bg='black', fg='#ffffff', text=languages_all['loading'], width=29)
        try:
            s.my_logo_label_warning.place(x=375, y=205)
        except tkinter.TclError:
            s.my_logo_label_warning.place(x=375, y=205)
        s.moving_device_frame(s.main_frame_adb)
        s.moving_software_info()

    def adb_close(s):
        def t_adb_close():
            global adb_server_all_flag, playGif_flag
            s.adb_test_close_disable.place(x=400, y=370)
            if tkinter.messagebox.askyesno(title=languages_all['exit'], message=languages_all['exit_message']):
                # 结束ADB测试工具相关程序
                s.close_str = tkinter.StringVar()
                s.close_label = tkinter.Label(s.root, width=50, height=10, bg='yellow', fg='red',
                                              textvariable=s.close_str,
                                              font=('宋体', 10))
                s.close_label.place(x=120, y=100)

                # 退出程序需要结束或处理任务
                s.close_str.set(languages_all['git_close'])
                gif = public.playGif(gif_new_path)  # 实例化gif动态播放对象
                gif.close()  # 删除动态gif临时文件和图片
                s.close_str.set(languages_all['killing_adb'])
                adb_server_all_flag = False  # 关闭工具时需要停止所有adb服务的行为
                playGif_flag = True  # 开启GIF缓存

                s.close_str.set(languages_all['frame_waiting'])
                # 关闭frame
                s.close_str.set(languages_all['adb_test_frame_close'])
                s.main_frame_adb.place_forget()  # 关闭主Frame

                with open(function_status, 'w') as fp:
                    fp.write('close')
                fp.close()
                print('ADB测试工具已完全退出！')
            try:
                s.close_label.place_forget()
            except AttributeError:
                pass
            s.adb_test_close_disable.place_forget()

        t_adb_close = threading.Thread(target=t_adb_close)
        t_adb_close.setDaemon(True)
        t_adb_close.start()

    def main_frame_adb_test(s):
        # 主frame
        s.main_frame_adb = tkinter.Frame(s.root, width=600, height=450)
        s.main_menu_bar(s.main_frame_adb)
        s.moving_device_frame(s.main_frame_adb)
        s.main_frame_adb.place(x=0, y=0)

    def main_menu_bar(s, main_frame_adb):
        # 切换窗口（选择模式）
        s.main_frame = tkinter.Frame(main_frame_adb, width=380, height=20)
        s.main_menu = tkinter.Menubutton(s.main_frame, text=languages_all['fast_name'])
        s.main_menu1 = tkinter.Menubutton(s.main_frame, text=languages_all['fast_name'])
        s.main_menu1.place(x=0, y=0)
        s.main_menu1.config(state='disable')
        s.screen_menu = tkinter.Menubutton(s.main_frame, text=languages_all['screen_record_name'])
        s.screen_menu1 = tkinter.Menubutton(s.main_frame, text=languages_all['screen_record_name'])
        s.screen_menu1.config(state='disable')

        s.install_menu = tkinter.Menubutton(s.main_frame, text=languages_all['install_uninstall_name'])
        s.install_menu1 = tkinter.Menubutton(s.main_frame, text=languages_all['install_uninstall_name'])
        s.install_menu1.config(state='disable')

        s.linux_menu = tkinter.Menubutton(s.main_frame, text=languages_all['linux_mode'])
        s.linux_menu1 = tkinter.Menubutton(s.main_frame, text=languages_all['linux_mode'])
        s.linux_menu1.config(state='disable')

        s.customize_menu = tkinter.Menubutton(s.main_frame, text=languages_all['customize_name'])
        s.customize_menu1 = tkinter.Menubutton(s.main_frame, text=languages_all['customize_name'])
        s.customize_menu1.config(state='disable')

        s.verion_menu = tkinter.Menubutton(s.main_frame, text=languages_all['version_history_name'])
        s.verion_menu1 = tkinter.Menubutton(s.main_frame, text=languages_all['version_history_name'])
        s.verion_menu1.config(state='disable')

        s.main_menu.bind('<Button-1>', lambda x: s.display_main_frame())
        s.verion_menu.bind('<Button-1>', lambda x: s.display_version_frame())
        s.screen_menu.bind('<Button-1>', lambda x: s.display_screenshot_frame())
        s.linux_menu.bind('<Button-1>', lambda x: s.display_linux_frame())
        s.install_menu.bind('<Button-1>', lambda x: s.display_install_frame())
        s.customize_menu.bind('<Button-1>', lambda x: s.display_customize_frame())

        s.main_menu.place(x=0, y=0)
        s.screen_menu.place(x=60, y=0)
        s.install_menu.place(x=120, y=0)
        s.linux_menu.place(x=180, y=0)
        s.customize_menu.place(x=240, y=0)
        s.verion_menu.place(x=305, y=0)
        s.main_frame.place(x=0, y=0)

        # 连接设备功能
        s.devices_state_label = tkinter.Label(main_frame_adb, text=languages_all['devices_state'])
        s.devices_null = tkinter.StringVar()
        s.devices_str = tkinter.StringVar()
        s.devices_success = tkinter.Label(main_frame_adb, textvariable=s.devices_str, fg='green')
        s.devices_fail = tkinter.Label(main_frame_adb, textvariable=s.devices_null, fg='red')
        s.devices_success.place(x=450, y=0)
        s.devices_state_label.config(command=s.devices_bind())
        s.devices_state_label.place(x=370, y=0)

        # 检测本地adb服务（None则使用内置adb）
        s.adb_state_label = tkinter.Label(main_frame_adb, text=languages_all['adb_state'])
        s.adb_state_label.config(command=s.adb_bind())
        s.adb_str = tkinter.StringVar()
        s.adb_success = tkinter.Label(main_frame_adb, textvariable=s.adb_str, fg='green')
        s.adb_str.set(languages_all['adb_service_state'])
        s.adb_success.place(x=110, y=425)
        s.adb_state_label.place(x=0, y=425)

        # 检测设备类型 Android Linux
        s.devices_type_label = tkinter.Label(main_frame_adb, text=languages_all['devices_type_state'])
        s.devices_type_str = tkinter.StringVar()
        s.devices_type_error = tkinter.StringVar()
        s.devices_type_success = tkinter.Label(main_frame_adb, textvariable=s.devices_type_str, fg='green')
        s.devices_type_fail = tkinter.Label(main_frame_adb, textvariable=s.devices_type_error, fg='red')
        s.devices_type_str.set(languages_all['devices_type_loading'])
        s.devices_type_label.place(x=270, y=425)
        s.devices_type_success.place(x=325, y=425)

        # 设备序列号下拉框说明
        content = languages_all['more_devices_content']
        s.more_devices_label = tkinter.Label(main_frame_adb, text=content, fg='red')
        s.more_devices_label.place(x=310, y=20)

        # 所有设备序列号下拉框选择
        s.more_devices_list = [' ']
        s.more_devices_value = tkinter.StringVar()
        s.more_devices_combobox = tkinter.ttk.Combobox(main_frame_adb, state="readonly", width=25,
                                                       textvariable=s.more_devices_value)
        # s.more_devices_combobox.config(command=s.more_devices_bind())
        # state：“正常”，“只读”或“禁用”之一。在“只读”状态下，可能无法直接编辑该值，并且用户只能从下拉列表中选择值。在“正常”状态下，文本字段可直接编辑。在“禁用”状态下，不可能进行交互。
        s.more_devices_combobox.place(x=380, y=80)

        # 循环单选按钮
        s.moving_str = tkinter.IntVar()
        s.moving_radio_button1 = tkinter.Radiobutton(main_frame_adb, variable=s.moving_str, value=0)
        s.moving_radio_button1.place(x=375, y=335)
        s.moving_radio_button2 = tkinter.Radiobutton(main_frame_adb, variable=s.moving_str, value=1)
        s.moving_radio_button2.place(x=390, y=335)
        # s.moving_radio_button1.config(command=s.moving_radio_bind())

        # 退出ADB测试工具按钮
        s.adb_test_close = tkinter.Button(main_frame_adb, text=languages_all['adb_test_exit_name'], width=width_button)
        s.adb_test_close_disable = tkinter.Button(main_frame_adb, text=languages_all['adb_test_exit_name'], width=width_button)
        s.adb_test_close_disable.config(state='disable')
        s.adb_test_close.bind('<Button-1>', lambda x: s.adb_close())
        s.adb_test_close.place(x=400, y=370)

        # log日志功能
        s.log_label = tkinter.Label(main_frame_adb, text=languages_all['open_log'],fg='red',cursor='hand2')  # underline 添加下划线
        s.log_label.config(font=("宋体",10, "underline"))
        # s.log_str = tkinter.StringVar()
        # s.devices_type_error = tkinter.StringVar()
        s.log_opened_label = tkinter.Label(main_frame_adb, text=languages_all['log_opened'], fg='green',cursor='hand2')
        s.log_opened_label.config(font=("宋体", 10, "underline"))
        s.log_stop_button = tkinter.Button(main_frame_adb,text=languages_all['log_stop'])
        public.CreateToolTip(s.log_label,languages_all['log_toast1'])
        public.CreateToolTip(s.log_opened_label,languages_all['log_toast2'])
        s.log_label.bind('<Button-1>', lambda x: log.update_log_state(s.devices_type_str.get(),s.log_label,s.log_opened_label,s.log_stop_button,s.more_devices_value.get(),s.adb_test_close,s.adb_test_close_disable))
        s.log_stop_button.bind('<Button-1>', lambda x: log.stop_log(s.more_devices_value.get(),s.log_stop_button,s.log_opened_label,s.log_label))
        s.log_label.place(x=450, y=425)

    def moving_device_frame(s, main_frame_adb):
        # 动态设备信息frame
        s.moving_device_frame1 = tkinter.Frame(main_frame_adb, width=210, height=220)

        # 设备类型
        s.devices_mode_str = tkinter.StringVar()
        s.devices_mode = tkinter.Label(s.moving_device_frame1, textvariable=s.devices_mode_str, width=29, bg='black',
                                       fg='#FFFFFF')
        s.devices_mode.place(x=0, y=0)
        # s.devices_mode.config(command=s.update_status())
        s.devices_mode_str.set(languages_all['moving_devices_state'])

        # 获取设备序列号（安卓+Linux）
        s.devices_sn_str = tkinter.StringVar()
        s.devices_sn = tkinter.Label(s.moving_device_frame1, textvariable=s.devices_sn_str, width=29, bg='black',
                                     fg='#FFFFFF')
        s.devices_sn.place(x=0, y=30)
        s.devices_sn_str.set(languages_all['android_devices_SN'])

        # 获取设备MAC（物理）地址
        s.devices_mac_str = tkinter.StringVar()
        s.devices_mac = tkinter.Label(s.moving_device_frame1, textvariable=s.devices_mac_str, width=29, bg='black',
                                      fg='#FFFFFF')
        s.devices_mac.place(x=0, y=60)
        s.devices_mac_str.set(languages_all['moving_devices_mac'])

        # 获取设备ip地址
        s.devices_ip_str = tkinter.StringVar()
        s.devices_ip = tkinter.Label(s.moving_device_frame1, textvariable=s.devices_ip_str, width=29, bg='black',
                                     fg='#FFFFFF')
        s.devices_ip.place(x=0, y=90)
        s.devices_ip_str.set(languages_all['moving_devices_ip'])

        # 获取安卓版本号  wraplength表示内容超过该宽度就会自动换行
        s.android_version_str = tkinter.StringVar()
        s.android_version = tkinter.Label(s.moving_device_frame1, textvariable=s.android_version_str, width=29,
                                          bg='black',
                                          fg='#FFFFFF', wraplength=200)
        s.android_version.place(x=0, y=120)
        s.android_version_str.set(languages_all['moving_devices_android_platform'])

        # 获取安卓的应用版本号和固件版本号
        s.software_version_str = tkinter.StringVar()
        s.software_version = tkinter.Label(s.moving_device_frame1, textvariable=s.software_version_str, width=29,
                                           bg='black',
                                           fg='#FFFFFF')
        s.software_version.place(x=0, y=150)
        s.software_version_str.set(languages_all['moving_devices_android_version'])
        s.firmware_version_str = tkinter.StringVar()
        s.firmware_version = tkinter.Label(s.moving_device_frame1, textvariable=s.firmware_version_str, width=29,
                                           bg='black', fg='#FFFFFF', wraplength=200)
        s.firmware_version.place(x=0, y=180)
        s.firmware_version_str.set(languages_all['moving_devices_android_firmware'])

    def moving_software_info(s):
        s.moving_software_info_frame = tkinter.Frame(s.main_frame_adb, width=210, height=220)
        # 个人常用头像
        if not os.path.exists(personal_photo_path):
            with open(personal_photo_path, 'w') as fp:
                fp.write('')
            fp.close()
        if not os.path.exists(personal_photo_origin):
            with open(personal_photo_origin, 'w') as fp:
                fp.write('')
            fp.close()
        s.my_logo_label = tkinter.Label(s.moving_software_info_frame, cursor='hand2')  # hand2光标放在标签上变为手的样式
        personal_logo_path = open(personal_photo_path, 'r').read()

        s.my_logo_remind_str = tkinter.StringVar()
        s.my_logo_remind_label = tkinter.Label(s.moving_software_info_frame, fg='red',
                                               textvariable=s.my_logo_remind_str,
                                               width=30, wraplength=200)
        s.my_logo_remind_label.place(x=0, y=125)

        type_file = personal_logo_path.split('\\')[-1].split('.')[-1]
        if personal_logo_path.strip() == '':
            my_log_photo = tkinter.PhotoImage(file=my_logo_path)
            s.my_logo_label.config(image=my_log_photo)
            s.my_logo_label.image = my_log_photo
            s.my_logo_remind_str.set(languages_all['my_logo_remind'])
        else:
            try:
                if type_file.strip() == 'gif':
                    s.init_gif_thread()
                else:
                    gif.close()  # 删除gif临时图
                    my_log_photo = tkinter.PhotoImage(file=personal_logo_path)
                    try:
                        s.my_logo_label.config(image=my_log_photo)
                        s.my_logo_label.image = my_log_photo
                    except tkinter.TclError:
                        pass
                personal_logo_origin = open(personal_photo_origin, 'r').read()
                if personal_logo_origin.strip() == '':
                    s.my_logo_remind_str.set(languages_all['my_logo_upload'])
                else:
                    photo_name = personal_logo_origin.split('\\')[-1]
                    s.my_logo_remind_str.set(languages_all['my_logo_file_name'] + photo_name)
            except tkinter.TclError:
                my_log_photo = tkinter.PhotoImage(file=my_logo_path)
                s.my_logo_label.config(image=my_log_photo)
                s.my_logo_label.image = my_log_photo
                s.my_logo_remind_str.set(languages_all['my_logo_remind'])
        s.my_logo_label.bind('<Button-1>', lambda x: s.my_logo_select())
        s.my_logo_label.place(x=45, y=10)

        # 个人简介信息
        my_info_content = languages_all['my_info_content']
        s.my_info_label = tkinter.Label(s.moving_software_info_frame, text=my_info_content, justify=tkinter.LEFT)
        s.my_info_label.place(x=10, y=165)

    def init_gif_thread(s):
        # 启动工具时默认把耗时的gif动态加载在线程中，以便快速启动工具，避免卡顿
        def t_init_gif():
            gif.playGif(s.moving_software_info_frame, s.my_logo_label)  # gif动态播放

        t_init_gif = threading.Thread(target=t_init_gif)
        t_init_gif.setDaemon = True
        t_init_gif.start()

    def my_logo_select(s):
        def t_my_logo_select():
            global gif
            # 选择并打开图像文件
            s.adb_test_close_disable.place(x=400, y=370)
            photoFilter = "Photo Files (*.jpg,*.jpeg,*.png,*.gif,*.bmp)|*.jpg;*.jpeg;*.png;*.gif;*.bmp|"  # so文件过滤
            dlg = win32ui.CreateFileDialog(True, "csv", None, 0x04 | 0x02, photoFilter)  # True表示打开文件对话框，0或False表示另存为对话框
            dlg.SetOFNInitialDir('C:\\Users\\' + getpass.getuser() + '\\Desktop')  # 设置打开文件对话框中的初始显示目录
            dlg.DoModal()  # 显示文件选择框
            photo_file = dlg.GetPathName()  # 获取选择的文件名称
            type_file = photo_file.split('\\')[-1].split('.')[-1]
            with open(personal_photo_origin, 'w') as fp:
                fp.write(photo_file)
            fp.close()
            # 更新个人图片
            if photo_file == '':
                pass
            else:
                if not os.path.exists(gif_new_save):
                    os.makedirs(gif_new_save)
                if type_file.strip() == 'gif':
                    gif.close()  # 结束播放并删除临时文件

                    # 修改gif图片大小，默认修改尺寸为111X101
                    s.my_logo_remind_str.set(languages_all['my_logo_gif_size'])
                    public.gif_size_revise(photo_file, 111, 101, gif_new_path)
                    s.my_logo_remind_str.set(languages_all['my_logo_gif_sucess'])
                    # my_log_photo = tkinter.PhotoImage(file=gif_new_path)
                    # s.my_logo_label.config(image=my_log_photo)
                    # s.my_logo_label.image = my_log_photo

                    # 实现gif图片动态播放
                    gif = public.playGif(gif_new_path)  # 实例化gif动态播放对象
                    gif.playGif(s.moving_software_info_frame, s.my_logo_label)

                    s.my_logo_remind_str.set(languages_all['my_logo_gif_application'])
                    with open(personal_photo_path, 'w') as fp:
                        fp.write(gif_new_path)
                    fp.close()
                else:
                    gif.close()  # 结束播放并删除临时文件
                    gif.stop(s.my_logo_label)
                    s.my_logo_label.place(x=45, y=10)

                    s.my_logo_remind_str.set(languages_all['my_logo_no_gif_size'])
                    public.not_gif_revise(photo_file, 111, 101, not_gif_new_path)
                    s.my_logo_remind_str.set(languages_all['my_logo_no_gif_sucess'])
                    my_log_photo = tkinter.PhotoImage(file=not_gif_new_path)
                    s.my_logo_label.config(image=my_log_photo)
                    s.my_logo_label.image = my_log_photo
                    s.my_logo_remind_str.set(languages_all['my_logo_no_gif_application'])
                    with open(personal_photo_path, 'w') as fp:
                        fp.write(not_gif_new_path)
                    fp.close()
            s.adb_test_close_disable.place_forget()

        t_my_logo_select = threading.Thread(target=t_my_logo_select)
        t_my_logo_select.setDaemon = True
        t_my_logo_select.start()

    def customize_button_disable(s):
        # 切换模块时先加载disable，以免误触
        global first_button_flag
        # 获取页面code
        try:
            if not os.path.exists(public.flow_page()):
                with open(public.flow_page()) as fp:
                    fp.write('')
                fp.close()
            flow_page = open(public.flow_page(), 'r').read()
            try:
                if first_button_flag and flow_page != '0':
                    s.flow_button_disable.place(x=20, y=20)
            except AttributeError:
                pass
        except FileNotFoundError:
            pass

    def display_main_frame(s):
        # 显示快捷模式主窗口
        with open(adb_model_text,'w') as fp:
            fp.write('quickly')
        s.quickly_frame()
        s.verion_menu1.place_forget()
        s.screen_menu1.place_forget()
        s.install_menu1.place_forget()
        s.linux_menu1.place_forget()
        s.customize_menu1.place_forget()
        s.main_menu1.place(x=0, y=0)
        try:
            s.screen_frame1.place_forget()
            s.linux_frame1.place_forget()
            s.verion_frame_full.place_forget()
            s.install_frame1.place_forget()
            s.customize_frame1.place_forget()
        except AttributeError:
            print('所选窗口未启动 -警告信息Logs（可忽略）')
            pass

    def display_screenshot_frame(s):
        # 显示截图录屏窗口
        with open(adb_model_text,'w') as fp:
            fp.write('screen')
        s.screen_frame()
        s.main_menu1.place_forget()
        s.linux_menu1.place_forget()
        s.install_menu1.place_forget()
        s.customize_menu1.place_forget()
        s.screen_menu1.place(x=60, y=0)
        s.verion_menu1.place_forget()
        try:
            s.quickly_frame1.place_forget()
            s.linux_frame1.place_forget()
            s.verion_frame_full.place_forget()
            s.install_frame1.place_forget()
            s.customize_frame1.place_forget()
        except AttributeError:
            print('所选窗口未启动 -警告信息Logs（可忽略）')
            pass

    def display_install_frame(s):
        # 显示安装卸载窗口
        with open(adb_model_text,'w') as fp:
            fp.write('install')
        s.install_menu1.place(x=120, y=0)
        s.install_frame()
        s.screen_menu1.place_forget()
        s.main_menu1.place_forget()
        s.verion_menu1.place_forget()
        s.linux_menu1.place_forget()
        s.customize_menu1.place_forget()
        try:
            s.quickly_frame1.place_forget()
            s.screen_frame1.place_forget()
            s.verion_frame_full.place_forget()
            s.linux_frame1.place_forget()
            s.customize_frame1.place_forget()
        except AttributeError:
            print('所选窗口未启动 -警告信息Logs（可忽略）')
            pass

        # 初始化按钮
        if apk_install_flag:
            s.apk_button_disable.place(x=20, y=325)
            s.apk_install_info_button_disable.place(x=200, y=325)
            s.install_str.set(languages_all['install_str'])

    def display_linux_frame(s):
        # 显示Linux模式窗口
        with open(adb_model_text,'w') as fp:
            fp.write('linux')
        s.linux_menu1.place(x=180, y=0)
        s.linux_frame()
        s.screen_menu1.place_forget()
        s.main_menu1.place_forget()
        s.verion_menu1.place_forget()
        s.install_menu1.place_forget()
        s.customize_menu1.place_forget()
        try:
            s.quickly_frame1.place_forget()
            s.screen_frame1.place_forget()
            s.verion_frame_full.place_forget()
            s.install_frame1.place_forget()
            s.customize_frame1.place_forget()
        except AttributeError:
            print('所选窗口未启动 -警告信息Logs（可忽略）')
            pass

    def display_customize_frame(s):
        # 显示自定义模式窗口
        with open(adb_model_text,'w') as fp:
            fp.write('customize')
        s.customize_menu1.place(x=240, y=0)
        s.customize_frame()
        s.customize_button_disable()  # 防误触
        s.main_menu1.place_forget()
        s.screen_menu1.place_forget()
        s.linux_menu1.place_forget()
        s.install_menu1.place_forget()
        s.verion_menu1.place_forget()
        try:
            s.linux_frame1.place_forget()
            s.quickly_frame1.place_forget()
            s.screen_frame1.place_forget()
            s.install_frame1.place_forget()
            s.verion_frame.place_forget()
        except AttributeError:
            print('所选窗口未启动 -警告信息Logs（可忽略）')
            pass

    def display_version_frame(s):
        # 显示版本历史窗口
        with open(adb_model_text,'w') as fp:
            fp.write('version_history')
        s.version_history_frame()
        s.main_menu1.place_forget()
        s.screen_menu1.place_forget()
        s.linux_menu1.place_forget()
        s.install_menu1.place_forget()
        s.customize_menu1.place_forget()
        s.verion_menu1.place(x=305, y=0)
        try:
            s.linux_frame1.place_forget()
            s.quickly_frame1.place_forget()
            s.screen_frame1.place_forget()
            s.install_frame1.place_forget()
        except AttributeError:
            print('所选窗口未启动 -警告信息Logs（可忽略）')
            pass

    def quickly_frame(s):
        s.quickly_frame1 = tkinter.Frame(s.main_frame_adb, width=width, height=height)

        # 返回功能
        s.back_button = tkinter.Button(s.quickly_frame1, text=languages_all['android_back'], width=width_button)
        s.back_button.bind('<Button-1>', lambda x: s.back_bind())
        s.back_button_disable = tkinter.Button(s.quickly_frame1, text=languages_all['android_backing'], width=width_button)
        s.back_button_disable.config(state='disable')
        s.back_button.place(x=20, y=20)

        # 进入系统设置功能
        s.settings_button = tkinter.Button(s.quickly_frame1, text=languages_all['android_setting'], width=width_button)
        s.settings_button.bind('<Button-1>', lambda x: s.settings_bind())
        s.settings_button_disable = tkinter.Button(s.quickly_frame1, text=languages_all['android_settings'], width=width_button)
        s.settings_button_disable.config(state='disable')
        s.settings_button.place(x=190, y=20)

        # 重启设备功能（通用）
        s.reboot_button = tkinter.Button(s.quickly_frame1, text=languages_all['android_reboot'], width=width_button)
        s.reboot_button.bind('<Button-1>', lambda x: s.reboot_bind())
        s.reboot_str = tkinter.StringVar()
        s.reboot_button_disable = tkinter.Button(s.quickly_frame1, textvariable=s.reboot_str, width=width_button)
        s.reboot_button_disable.config(state='disable')
        s.reboot_button.place(x=20, y=60)

        # 关机设备功能
        s.shutdown_button = tkinter.Button(s.quickly_frame1, text=languages_all['android_shutdown'], width=width_button)
        s.shutdown_button.bind('<Button-1>', lambda x: s.shutdown_bind())
        s.shutdown_button_disable = tkinter.Button(s.quickly_frame1, text=languages_all['android_shutdowning'], width=width_button)
        s.shutdown_button_disable.config(state='disable')
        s.shutdown_button.place(x=190, y=60)

        # 清理缓存（初始化）功能
        s.clear_button = tkinter.Button(s.quickly_frame1, text=languages_all['android_clean'], width=width_button)
        s.clear_button.bind('<Button-1>', lambda x: s.clear_bind())
        s.clear_button_disable = tkinter.Button(s.quickly_frame1, text=languages_all['android_cleanning'], width=width_button)
        s.clear_button_disable.config(state='disable')
        s.clear_button.place(x=20, y=100)

        # 终止（结束）程序
        s.kill_button = tkinter.Button(s.quickly_frame1, text=languages_all['android_close'], width=width_button)
        s.kill_button.bind('<Button-1>', lambda x: s.kill_bind())
        s.kill_button_disable = tkinter.Button(s.quickly_frame1, text=languages_all['android_closeing'], width=width_button)
        s.kill_button_disable.config(state='disable')
        s.kill_button.place(x=190, y=100)

        # 返回Launcher桌面
        s.desktop_button = tkinter.Button(s.quickly_frame1, text=languages_all['android_back_launcher'], width=width_button)
        s.desktop_button.bind('<Button-1>', lambda x: s.desktop_bind())
        s.desktop_button_disable = tkinter.Button(s.quickly_frame1, text=languages_all['android_back_launchering'], width=width_button)
        s.desktop_button_disable.config(state='disable')
        s.desktop_button.place(x=20, y=140)

        # 唤醒屏幕
        s.awake_button = tkinter.Button(s.quickly_frame1, text=languages_all['android_awake'], width=width_button)
        s.awake_button.bind('<Button-1>', lambda x: s.awake_bind())
        s.awake_button_disable = tkinter.Button(s.quickly_frame1, text=languages_all['android_awaking'], width=width_button)
        s.awake_button_disable.config(state='disable')
        s.awake_button.place(x=190, y=140)

        # 关机设备功能（Linux）
        s.linux_shutdown_button = tkinter.Button(s.quickly_frame1, text=languages_all['linux_shutdown'], width=width_button)
        s.linux_shutdown_button.bind('<Button-1>', lambda x: s.linux_shutdown_bind())
        s.linux_shutdown_button_disable = tkinter.Button(s.quickly_frame1, text=languages_all['android_shutdowning'], width=width_button)
        s.linux_shutdown_button_disable.config(state='disable')
        s.linux_shutdown_button.place(x=20, y=180)

        # 一键复制SN序列号功能（通用）
        s.copy_SN_button = tkinter.Button(s.quickly_frame1, text=languages_all['copy_sn'], width=width_button)
        s.copy_SN_button.bind('<Button-1>', lambda x: s.copy_SN_bind())
        s.copy_SN_button_disable = tkinter.Button(s.quickly_frame1, text=languages_all['copying_sn'], width=width_button)
        s.copy_SN_button_disable.config(state='disable')
        s.copy_SN_button.place(x=190, y=180)

        # 使用说明
        content = languages_all['quickly_content']
        s.instructions_label = tkinter.Label(s.quickly_frame1, text=content, fg='red')
        s.instructions_label.place(x=20, y=220)
        s.quickly_frame1.place(y=20)

    def screen_frame(s):
        # 截图录屏窗口
        s.screen_frame1 = tkinter.Frame(s.main_frame_adb, width=width, height=height)

        # 截图状态栏
        s.screen_str = tkinter.StringVar()
        s.screenshut_label = tkinter.Label(s.screen_frame1, textvariable=s.screen_str, bg='black', fg='#FFFFFF',
                                           width=46, height=2)
        s.screenshut_label.place(x=20, y=20)
        s.screen_str.set(languages_all['screen_state'])

        # 截图文件名
        s.screen_entry = tkinter.Entry(s.screen_frame1, width=35)
        s.screenshut_star = tkinter.Label(s.screen_frame1, text='*', fg='red', font=('宋体', 15))
        s.screen_entry.insert(tkinter.END, 'test')
        s.screen_entry.place(x=50, y=80)
        s.screenshut_star.place(x=300, y=80)

        # 截图文件名说明
        content = languages_all['screen_file_content']
        s.screen_readme_label = tkinter.Label(s.screen_frame1, text=content, fg='red', font=('宋体', 10))
        s.screen_readme_label.place(x=20, y=100)

        # 截图按钮
        s.screen_button = tkinter.Button(s.screen_frame1, text=languages_all['screen_start'], width=width_button)
        s.screen_button.bind('<Button-1>', lambda x: s.screenshot_bind())
        s.screen_button_disable = tkinter.Button(s.screen_frame1, text=languages_all['screen_doing'], width=width_button)
        s.screen_button_disable.config(state='disable')
        s.screen_button.place(x=20, y=140)

        # 打开截图文件夹按钮
        s.open_screen_button = tkinter.Button(s.screen_frame1, text=languages_all['screen_open'], width=width_button)
        s.open_screen_button.bind('<Button-1>', lambda x: s.open_screen_bind())
        s.open_screen_button_disable = tkinter.Button(s.screen_frame1, text=languages_all['screen_opening'], width=width_button)
        s.open_screen_button_disable.config(state='disable')
        s.open_screen_button.place(x=200, y=140)

        # 录屏状态栏
        s.record_str = tkinter.StringVar()
        s.record_label = tkinter.Label(s.screen_frame1, textvariable=s.record_str, bg='black', fg='#FFFFFF',
                                       width=46, height=2)
        s.record_label.place(x=20, y=180)
        s.record_str.set(languages_all['record_state'])

        # 录屏文件名
        s.record_entry = tkinter.Entry(s.screen_frame1, width=35)
        s.record_star = tkinter.Label(s.screen_frame1, text='*', fg='red', font=('宋体', 15))
        s.record_entry.insert(tkinter.END, 'demo')
        s.record_entry.place(x=50, y=230)
        s.record_star.place(x=300, y=230)

        # 录屏文件名说明
        # s.record_readme_label = tkinter.Label(s.screen_frame1, text=content, fg='red', font=('宋体', 10))
        s.record_readme_button = tkinter.Button(s.screen_frame1, text=languages_all['record_content'], width=width_button)
        s.record_readme_button.bind('<Button-1>', lambda x: s.record_readme_bind())
        s.record_readme_button.place(x=120, y=260)

        # 录屏时间说明
        content = languages_all['record_time']
        s.record_time_label = tkinter.Label(s.screen_frame1, text=content)
        s.record_time_label.place(x=20, y=300)

        # 录屏时间下拉框
        s.record_time = tkinter.StringVar()
        s.record_combobox = tkinter.ttk.Combobox(s.screen_frame1, state="readonly", width=5, textvariable=s.record_time)
        # state：“正常”，“只读”或“禁用”之一。在“只读”状态下，可能无法直接编辑该值，并且用户只能从下拉列表中选择值。在“正常”状态下，文本字段可直接编辑。在“禁用”状态下，不可能进行交互。
        seconds = languages_all['record_seconds']
        s.record_combobox['value'] = ('180' + seconds, '120' + seconds, '60' + seconds, '30' + seconds, '10' + seconds)
        s.record_combobox.current(0)
        s.record_combobox.place(x=120, y=300)

        # 录屏模式单选按钮
        s.record_model_str = tkinter.IntVar()
        s.record_radio_button1 = tkinter.Radiobutton(s.screen_frame1, text=languages_all['record_manual'], variable=s.record_model_str, value=0)
        s.record_radio_button1.place(x=200, y=300)
        s.record_radio_button2 = tkinter.Radiobutton(s.screen_frame1, text=languages_all['record_continuous'], variable=s.record_model_str, value=1)
        s.record_radio_button2.place(x=270, y=300)
        # 气泡提示对话框
        public.CreateToolTip(s.record_radio_button1, text=languages_all['record_manual_content'])
        public.CreateToolTip(s.record_radio_button2, text=languages_all['record_continuous_content'])

        # 录屏按钮
        s.record_button = tkinter.Button(s.screen_frame1, text=languages_all['record_start'], width=width_button)
        s.record_button.bind('<Button-1>', lambda x: s.record_bind())
        s.record_button_disable = tkinter.Button(s.screen_frame1, text=languages_all['record_doing'], width=width_button)
        s.record_button_disable.config(state='disable')
        s.record_button.place(x=20, y=330)

        # 停止录屏按钮
        s.record_stop_button = tkinter.Button(s.screen_frame1, text=languages_all['record_stop'], width=width_button)
        s.record_stop_button.bind('<Button-1>', lambda x: s.record_stop_bind())
        s.record_stop_button_disable = tkinter.Button(s.screen_frame1, text=languages_all['record_stop'], width=width_button)
        s.record_stop_button_disable.config(state='disable')
        s.record_stop_button_disable.place(x=200, y=330)

        # 打开录屏文件夹按钮
        s.open_record_button = tkinter.Button(s.screen_frame1, text=languages_all['record_open'], width=width_button)
        s.open_record_button.bind('<Button-1>', lambda x: s.open_record_bind())
        s.open_record_button_disable = tkinter.Button(s.screen_frame1, text=languages_all['screen_opening'], width=width_button)
        s.open_record_button_disable.config(state='disable')
        s.open_record_button.place(x=20, y=370)

        # 一键重置按钮
        s.reset_button = tkinter.Button(s.screen_frame1, text=languages_all['record_reset'], width=width_button)
        s.reset_button.bind('<Button-1>', lambda x: s.reset_bind())
        s.reset_button_disable = tkinter.Button(s.screen_frame1, text=languages_all['record_reset'], width=width_button)
        s.reset_button_disable.config(state='disable')
        s.reset_button_disable.bind('<Button-1>', lambda x: s.reset_disable_bind())
        s.reset_button.place(x=200, y=370)

        s.screen_frame1.place(y=20)

    def record_readme_bind(s):
        def t_record_readme():
            # 显示录屏注意事项内容
            content = languages_all['record_file_content']
            tkinter.messagebox.showinfo(languages_all['record_warining'], content)

        t_record_readme = threading.Thread(target=t_record_readme)
        t_record_readme.setDaemon(True)
        t_record_readme.start()

    @adb_tools_log
    def install_frame(s):
        # 显示安装与卸载模式窗口
        s.install_frame1 = tkinter.Frame(s.main_frame_adb, width=width, height=height)

        # 卸载状态栏
        s.uninstall_str = tkinter.StringVar()
        s.uninstall_label = tkinter.Label(s.install_frame1, textvariable=s.uninstall_str, bg='black', fg='#FFFFFF',
                                          width=46, height=2)
        s.uninstall_label.place(x=20, y=20)
        s.uninstall_str.set(languages_all['uninstall_state'])

        # 检测包名按钮
        s.check_package_name_button = tkinter.Button(s.install_frame1, text=languages_all['found_package'], width=width_button)
        s.check_package_name_button.bind('<Button-1>', lambda x: s.check_package_name_bind(uninstall_flag))
        s.check_package_name_button_disable = tkinter.Button(s.install_frame1, text=languages_all['found_doing'], width=width_button)
        s.check_package_name_button_disable.config(state='disable')
        s.check_package_name_button.place(x=20, y=80)

        # 卸载APk按钮
        s.uninstall_button = tkinter.Button(s.install_frame1, text=languages_all['uninstall_apk'], width=width_button)
        s.uninstall_button.bind('<Button-1>', lambda x: s.uninstall_bind())
        s.uninstall_button_disable = tkinter.Button(s.install_frame1, text=languages_all['uninstall_doing'], width=width_button)
        s.uninstall_button_disable.config(state='disable')
        s.uninstall_button.place(x=200, y=80)

        # 检测包名说明
        check_package_content = languages_all['uninstall_content']
        s.check_package_label = tkinter.Label(s.install_frame1, fg='red', text=check_package_content)
        s.check_package_label.place(x=20, y=120)

        # apk包文件路径单行文本框
        s.apk_path_package_str = tkinter.StringVar()
        s.apk_path_package_entry = tkinter.Entry(s.install_frame1, textvariable=(s.apk_path_package_str),
                                                 width=40, highlightcolor='yellow', validate="focusin"
                                                 , highlightthickness=5)
        s.apk_path_package_entry.place(x=20, y=160)

        # apk文件获取路径拖拽功能（windnd）
        public.windnd_hook_files(s.apk_path_package_entry, s.apk_path_package_str)
        if not os.path.exists(apk_path_package_log):
            with open(apk_path_package_log, 'w') as fp:
                fp.write('')
            fp.close()
        path_msg = open(apk_path_package_log, 'r').read()
        s.apk_path_package_entry.insert(tkinter.END, path_msg)

        # 浏览apk文件按钮
        s.apk_path_package_button = tkinter.Button(s.install_frame1, text=languages_all['browse'])
        s.apk_path_package_button_disable = tkinter.Button(s.install_frame1, text=languages_all['browse'])
        s.apk_path_package_button.bind('<Button-1>', lambda x: s.open_apk_path_files(apk_path_install_flag))
        s.apk_path_package_button_disable.config(state='disable')
        s.apk_path_package_button.place(x=320, y=160)

        # 检测apk文件包名按钮
        s.apk_package_button = tkinter.Button(s.install_frame1, text=languages_all['get_apk_info'], width=width_button)
        s.apk_package_button_disable = tkinter.Button(s.install_frame1, text=languages_all['getting_apk_info'], width=width_button)
        s.apk_package_button_disable.config(state='disable')
        s.apk_package_button.bind('<Button-1>', lambda x: s.apk_package_bind())
        s.apk_package_button.place(x=20, y=200)

        # 一键复制粘贴apk包名按钮
        s.apk_package_copy_button = tkinter.Button(s.install_frame1, text=languages_all['copy_apk_info'], width=width_button)
        s.apk_package_copy_button_disable = tkinter.Button(s.install_frame1, text=languages_all['copying_apk_info'], width=width_button)
        s.apk_package_copy_button_disable.config(state='disable')
        s.apk_package_copy_button.bind('<Button-1>', lambda x: s.apk_package_copy_bind())
        s.apk_package_copy_button.place(x=200, y=200)

        # 安装状态栏
        s.install_str = tkinter.StringVar()
        s.install_label = tkinter.Label(s.install_frame1, textvariable=s.install_str, bg='black', fg='#FFFFFF',
                                        width=46, height=2)
        s.install_label.place(x=20, y=240)
        s.install_str.set(languages_all['install_state'])

        # 安装apk单行文本框
        s.apk_path_str = tkinter.StringVar()
        s.apk_path_entry = tkinter.Entry(s.install_frame1, textvariable=s.apk_path_str,
                                         width=40, highlightcolor='yellow', validate="focusin"
                                         , highlightthickness=5)
        s.apk_path_entry.place(x=20, y=285)

        # 安装apk拖拽功能（windnd）
        public.windnd_hook_files(s.apk_path_entry, s.apk_path_str)
        if not os.path.exists(apk_path_log):
            with open(apk_path_log, 'w') as fp:
                fp.write('')
            fp.close()
        apk_path_msg = open(apk_path_log, 'r').read()
        s.apk_path_entry.insert(tkinter.END, apk_path_msg)

        # 浏览apk文件按钮（安装apk）
        s.apk_path_button = tkinter.Button(s.install_frame1, text=languages_all['browse'])
        s.apk_path_button_disable = tkinter.Button(s.install_frame1, text=languages_all['browse'])
        s.apk_path_button.bind('<Button-1>', lambda x: s.apk_path_insatll_bind())
        s.apk_path_button_disable.config(state='disable')
        s.apk_path_button.place(x=320, y=285)

        # 安装apk文件按钮
        s.apk_button = tkinter.Button(s.install_frame1, text=languages_all['install_apk'], width=width_button)
        s.apk_button_disable = tkinter.Button(s.install_frame1, text=languages_all['install_doing'], width=width_button)
        s.apk_button_disable.config(state='disable')
        s.apk_button.bind('<Button-1>', lambda x: s.apk_install_bind())
        s.apk_button.place(x=20, y=325)

        # 查看安装信息按钮
        s.apk_install_info_button = tkinter.Button(s.install_frame1, text=languages_all['install_info'], width=width_button)
        s.apk_install_info_button_disable = tkinter.Button(s.install_frame1, text=languages_all['install_info'], width=width_button)
        s.apk_install_info_button_disable.config(state='disable')
        s.apk_install_info_button.bind('<Button-1>', lambda x: s.apk_install_info_bind())
        s.apk_install_info_button.place(x=200, y=325)

        # 选择apk安装模式label
        s.apk_install_mode_label = tkinter.Label(s.install_frame1, text=languages_all['install_mode'])
        s.apk_install_mode_label.place(x=20, y=365)

        # apk安装模式下拉框选择
        s.apk_install_mode_value = tkinter.StringVar()
        s.apk_install_mode_combobox = tkinter.ttk.Combobox(s.install_frame1, state="readonly", width=25,
                                                           textvariable=s.apk_install_mode_value)
        s.apk_install_mode_combobox['value'] = (languages_all['install_mode_default'],languages_all['install_mode_d'])
        s.apk_install_mode_combobox.current(0)
        # state：“正常”，“只读”或“禁用”之一。在“只读”状态下，可能无法直接编辑该值，并且用户只能从下拉列表中选择值。在“正常”状态下，文本字段可直接编辑。在“禁用”状态下，不可能进行交互。
        s.apk_install_mode_combobox.place(x=120, y=365)

        s.install_frame1.place(y=20)

    def linux_frame(s):
        global photo  # 函数运行结束就被回收了，会显示的是空白
        # 显示Linux模式窗口
        s.linux_frame1 = tkinter.Frame(s.main_frame_adb, width=width, height=height)

        # 设备初始化说明
        init_content = languages_all['linux_init_content']
        s.init_label = tkinter.Label(s.linux_frame1, text=init_content, fg='red', font=('宋体', 10))
        s.init_label.place(x=20, y=20)

        img = Image.open(linux_debug_logo_path)
        photo = ImageTk.PhotoImage(img)
        s.debug_label = tkinter.Label(s.linux_frame1,image=photo)
        s.debug_label.place(x=320,y=25)
        s.debug_label.bind('<Button-1>',lambda x:s.linux_debug())
        content = '''该处为Linux设备快速调试模式：
点击“是”后会开启快速调试模式，设备将会非正常初始化且不会重启设备，快速使用
Linux模式所有功能，但注意以下几点：
（1）推荐使用不影响上传到设备的功能
（2）请不要使用安装功能，否则出现异常
（3）警告只会提示一次，开启该模式后，设备尽快重启一次以便正常初始化
（4）此功能为本人专用调试模式，未经本人允许使用自己看着办~'''
        public.CreateToolTip(s.debug_label,content)

        # 初始化按钮
        s.init_str = tkinter.StringVar()
        s.linux_init_Button = tkinter.Button(s.linux_frame1, text=languages_all['linux_init_devices'], width=width_button)
        s.linux_init_Button_disable = tkinter.Button(s.linux_frame1, text=languages_all['linux_init_devices'], width=width_button)
        s.linux_init_Button_disable.config(state='disable')
        s.linux_init_Button.bind('<Button-1>', lambda x: linux_main.devices_init(s.init_str, s.linux_init_Button
                                                                                 , s.linux_init_Button_disable,
                                                                                 s.more_devices_value.get(),
                                                                                 s.init_again_Button_disable))
        s.linux_init_Button_disable.place(x=200, y=110)

        s.linux_type_str = tkinter.StringVar()  # 先定义在前面防止报错 - 设备固件方案商类型及下拉列表

        # 重新检测按钮
        s.init_again_Button = tkinter.Button(s.linux_frame1, text=languages_all['linux_init_found'], width=width_button)
        s.init_again_Button_disable = tkinter.Button(s.linux_frame1, text=languages_all['found_doing'], width=width_button)
        s.init_again_Button_disable.config(state='disable')
        s.init_again_Button.bind('<Button-1>', lambda x: linux_main.check_init(s.init_str, s.linux_init_Button
                                                                               , s.linux_init_Button_disable,
                                                                               devices_linux_flag,
                                                                               s.linux_all_button_close
                                                                               , s.more_devices_value.get(),
                                                                               s.init_again_Button_disable,
                                                                               s.linux_type_str.get()))
        s.init_again_Button.place(x=20, y=110)

        # 初始化状态栏
        s.init_label = tkinter.Label(s.linux_frame1, textvariable=s.init_str, bg='black', fg='#FFFFFF',
                                     width=46, height=2)
        s.init_label.config(command=linux_main.check_init(s.init_str, s.linux_init_Button, s.linux_init_Button_disable,
                                                          devices_linux_flag, s.linux_all_button_close,
                                                          s.more_devices_value.get(),
                                                          s.init_again_Button_disable, s.linux_type_str.get()))
        s.init_label.place(x=20, y=60)
        s.init_str.set(languages_all['linux_init_state'])

        # 初始化按钮
        s.linux_extra_Button = tkinter.Button(s.linux_frame1, text=languages_all['linux_quickly'], width=width_button)
        s.linux_extra_Button_disable = tkinter.Button(s.linux_frame1, text=languages_all['linux_quickly'], width=width_button)
        s.linux_extra_Button_disable.config(state='disable')
        s.linux_extra_Button.bind('<Button-1>', lambda x: s.linux_extra_bind())
        s.linux_extra_Button.place(x=20, y=155)

        # 设备固件方案商类型及下拉列表
        s.linux_type_label = tkinter.Label(s.linux_frame1)
        linux_type_picture = tkinter.PhotoImage(file=linux_type_photo)
        s.linux_type_label.config(image=linux_type_picture)
        s.linux_type_label.image = linux_type_picture
        s.linux_type_label.place(x=175, y=155)
        content = languages_all['linux_firmware_content']
        public.CreateToolTip(s.linux_type_label, content)

        s.linux_type_combobox = tkinter.ttk.Combobox(s.linux_frame1, textvariable=s.linux_type_str, width=18)
        s.linux_type_combobox['value'] = [languages_all['linux_firmware_quanzhi'], languages_all['linux_firmware_extra']]
        s.linux_type_combobox.config(state='readonly')
        s.linux_type_combobox.current(0)
        s.linux_type_combobox.place(x=210, y=160)

        # 功能禁用状态标签
        button_disable_content = languages_all['linux_disable_content']
        s.linux_button_label = tkinter.Label(s.linux_frame1, text=button_disable_content, fg='red',
                                             width=46, height=8)
        s.linux_button_bind()

        # 截图功能
        s.linux_screen_Button = tkinter.Button(s.linux_frame1, text=languages_all['linux_screen'], width=width_button)
        s.linux_screen_Button_disable = tkinter.Button(s.linux_frame1, text=languages_all['linux_screen'], width=width_button)
        s.linux_screen_Button.bind('<Button-1>', lambda x: s.linux_screen_bind())
        s.linux_screen_Button_disable.config(state='disable')
        s.linux_screen_Button.place(x=20, y=190)

        # 关闭开发者模式
        s.linux_developer_mode_Button_close = tkinter.Button(s.linux_frame1, text=languages_all['linux_local'], width=width_button)
        s.linux_developer_mode_Button_close_disable = tkinter.Button(s.linux_frame1, text=languages_all['adb_mode_disable'],
                                                                     width=width_button)
        s.linux_developer_mode_Button_close.bind('<Button-1>', lambda x: s.linux_developer_mode_close_bind())
        s.linux_developer_mode_Button_close_disable.config(state='disable')
        s.linux_developer_mode_Button_close.place(x=200, y=190)
        s.linux_developer_mode_content = languages_all['adb_mode_disable_content']
        public.CreateToolTip(s.linux_developer_mode_Button_close, s.linux_developer_mode_content)

        # 安装软件
        s.linux_install = tkinter.Button(s.linux_frame1, text=languages_all['linux_install'], width=width_button)
        s.linux_install_disable = tkinter.Button(s.linux_frame1, text=languages_all['linux_install'], width=width_button)
        s.linux_install.bind('<Button-1>', lambda x: s.linux_install_bind())
        s.linux_install_disable.config(state='disable')
        s.linux_install.place(x=20, y=230)

        # 一键取图
        s.linux_camera = tkinter.Button(s.linux_frame1, text=languages_all['linux_get_yuv'], width=width_button)
        s.linux_camera_disable = tkinter.Button(s.linux_frame1, text=languages_all['linux_get_yuv'], width=width_button)
        s.linux_camera.bind('<Button-1>', lambda x: s.linux_camera_bind())
        s.linux_camera_disable.config(state='disable')
        s.linux_camera.place(x=20, y=270)

        # 写号工具
        s.write_number = tkinter.Button(s.linux_frame1, text=languages_all['linux_write_sn'], width=width_button)
        s.write_number_disable = tkinter.Button(s.linux_frame1, text=languages_all['linux_write_sn'], width=width_button)
        s.write_number.bind('<Button-1>', lambda x: s.write_number_bind())
        s.write_number_disable.config(state='disable')
        s.write_number.place(x=200, y=230)

        # 一键获取日志
        s.get_log = tkinter.Button(s.linux_frame1, text=languages_all['linux_get_log'], width=width_button)
        s.get_log_disable = tkinter.Button(s.linux_frame1, text=languages_all['linux_get_log'], width=width_button)
        s.get_log.bind('<Button-1>', lambda x: s.get_log_bind())
        s.get_log_disable.config(state='disable')
        s.get_log.place(x=200, y=270)

        # UUID状态栏
        s.uuid_str = tkinter.StringVar()
        s.uuid_label = tkinter.Label(s.linux_frame1, textvariable=s.uuid_str, bg='black', fg='#FFFFFF',
                                     width=46, height=2)
        s.uuid_label.place(x=20, y=310)

        # UUID重复获取功能
        s.uuid_get = tkinter.Button(s.linux_frame1, text=languages_all['linux_get_uuid'], width=width_button)
        s.uuid_get_disable = tkinter.Button(s.linux_frame1, text=languages_all['linux_geting_uuid'], width=width_button)
        s.uuid_get.bind('<Button-1>', lambda x: s.uuid_main_bind())
        s.uuid_get_disable.config(state='disable')
        s.uuid_get.place(x=20, y=360)
        
        # UUID复制粘贴功能
        s.uuid_paste = tkinter.Button(s.linux_frame1, text=languages_all['linux_copy_uuid'], width=width_button)
        s.uuid_paste_disable = tkinter.Button(s.linux_frame1, text=languages_all['linux_copying_uuid'], width=width_button)
        s.uuid_paste.bind('<Button-1>', lambda x: s.uuid_paste_bind())
        s.uuid_paste_disable.config(state='disable')
        s.uuid_paste.place(x=200, y=360)

        # 开始默认禁用，根据情况开启
        s.linux_all_button_close()

        s.linux_frame1.place(y=20)

    def customize_frame(s):
        s.customize_frame1 = tkinter.Frame(s.main_frame_adb, width=width, height=height)

        # 查询设备应用流量值
        s.flow_button = tkinter.Button(s.customize_frame1, text=languages_all['flow_value'], width=width_button)
        s.flow_button.bind('<Button-1>', lambda x: s.flow_bind())
        s.flow_button_disable = tkinter.Button(s.customize_frame1, text=languages_all['flow_value'], width=width_button)
        s.flow_button_disable.config(state='disable')
        s.flow_button.place(x=20, y=20)

        if 'flow' in page_state_list:
            s.flow_button.place_forget()
            s.flow_button_disable.place(x=20, y=20)
            customize_main.flow_page_state(s.flow_button,s.flow_button_disable)

        # 查询文件MD5 和 大小
        s.md5_size_button = tkinter.Button(s.customize_frame1, text=languages_all['get_md5_count'], width=width_button)
        s.md5_size_button.bind('<Button-1>', lambda x: s.md5_size_bind())
        s.md5_size_button_disable = tkinter.Button(s.customize_frame1, text=languages_all['get_md5_count'], width=width_button)
        s.md5_size_button_disable.config(state='disable')
        s.md5_size_button.place(x=200, y=20)

        if 'md5_size' in page_state_list:
            s.md5_size_button.pack_forget()
            s.md5_size_button_disable.place(x=200, y=20)
            customize_main.md5_page_state(s.md5_size_button, s.md5_size_button_disable)

        # monkey按钮
        monkey.monkey_flame(s.customize_frame1,width_button,s.adb_test_close_disable,page_state_list)

        # adb_shell 终端
        AdbShell().adb_shell_cmd(s.customize_frame1,width_button,s.adb_test_close_disable,page_state_list,s.adb_test_close)

        # 上传push下载pull功能
        push_pull = customize_main.PushPull()
        push_pull.push_pull_form(s.customize_frame1,width_button,s.adb_test_close_disable,page_state_list,s.adb_test_close)

        s.customize_frame1.place(y=20)

    def linux_all_button_close(s):
        def linux_all_button_place_forget():
            global uuid_server_flag, linux_Initialize_flag
            global uuid_reboot_flag
            global uuid_run_flag,linux_button_flag

            # 特殊情况下禁用linux模式所有功能（包含已disable状态的按钮）
            s.linux_screen_Button.place_forget()
            s.linux_screen_Button_disable.place_forget()
            s.linux_developer_mode_Button_close.place_forget()
            s.linux_developer_mode_Button_close_disable.place_forget()
            s.linux_install.place_forget()
            s.linux_install_disable.place_forget()
            s.linux_camera.place_forget()
            s.linux_camera_disable.place_forget()
            s.write_number.place_forget()
            s.write_number_disable.place_forget()
            s.uuid_label.place_forget()
            s.uuid_paste.place_forget()
            s.uuid_paste_disable.place_forget()
            s.uuid_get.place_forget()
            s.uuid_get_disable.place_forget()
            s.get_log.place_forget()
            s.get_log_disable.place_forget()
            s.linux_extra_Button.place_forget()
            s.linux_extra_Button_disable.place_forget()

            # 恢复绑定事件的标识
            if not uuid_reboot_flag:
                uuid_server_flag = False
            else:
                pass
            uuid_run_flag = False

            devices_state = public.device_connect()
            if devices_state and not linux_Initialize_flag:
                # 每次连接设备仅启动一次（新增每次连接Linux设备时都会检测一遍是否初始化）
                linux_main.check_init(s.init_str, s.linux_init_Button
                                      , s.linux_init_Button_disable, devices_linux_flag, s.linux_all_button_close
                                      , s.more_devices_value.get(), s.init_again_Button_disable, s.linux_type_str.get())
                linux_Initialize_flag = True
                linux_button_flag = False

            s.linux_button_label.place(x=20, y=220)

        devices = public.device_connect()
        if not devices:
            s.linux_init_Button.place_forget()
            s.linux_init_Button_disable.place(x=200, y=110)

            linux_all_button_place_forget()
        else:
            linux_all_button_place_forget()

    def linux_all_button_open(s):  # 获取或显示Linux所有功能
        global uuid_server_flag, linux_Initialize_flag,linux_button_flag

        # 先禁用初始化按钮
        s.linux_init_Button.place_forget()
        s.linux_init_Button_disable.place(x=200, y=110)

        # 先初始化按钮状态
        if not os.path.exists(screen_page):
            with open(screen_page, 'w') as fp:
                fp.write('0')
        if not os.path.exists(install_page):
            with open(install_page, 'w') as fp:
                fp.write('0')
        if not os.path.exists(camera_page):
            with open(camera_page, 'w') as fp:
                fp.write('0')
        if not os.path.exists(write_number_page):
            with open(write_number_page, 'w') as fp:
                fp.write('0')
        if not os.path.exists(get_log_page):
            with open(get_log_page, 'w') as fp:
                fp.write('0')
        if not os.path.exists(public.linux_extra_page()):
            with open(public.linux_extra_page(), 'w') as fp:
                fp.write('0')

        # 读取一次Linux所有页面状态
        screen_page_state = open(screen_page, 'r').read()
        install_page_state = open(install_page, 'r').read()
        camera_page_state = open(camera_page, 'r').read()
        write_number_page_state = open(write_number_page, 'r').read()
        get_log_page_state = open(get_log_page, 'r').read()
        linux_extra_page_state = open(public.linux_extra_page(), 'r').read()
        if screen_page_state == '':
            s.linux_screen_Button_disable.place(x=20, y=190)
            s.adb_test_close_disable.place(x=400, y=370)
        else:
            s.linux_screen_Button_disable.place_forget()
            s.linux_screen_Button.place(x=20, y=190)
        if install_page_state == '':
            s.linux_install_disable.place(x=20, y=230)
            s.adb_test_close_disable.place(x=400, y=370)
        else:
            s.linux_install_disable.place_forget()
            s.linux_install.place(x=20, y=230)
        if camera_page_state == '':
            s.linux_camera_disable.place(x=20, y=270)
            s.adb_test_close_disable.place(x=400, y=370)
        else:
            s.linux_camera_disable.place_forget()
            s.linux_camera.place(x=20, y=270)
        if write_number_page_state == '':
            s.write_number_disable.place(x=200, y=230)
            s.adb_test_close_disable.place(x=400, y=370)
        else:
            s.write_number_disable.place_forget()
            s.write_number.place(x=200, y=230)
        if get_log_page_state == '':
            s.get_log_disable.place(x=200, y=270)
            s.adb_test_close_disable.place(x=400, y=370)
        else:
            s.get_log_disable.place_forget()
            s.get_log.place(x=200, y=270)
        if linux_extra_page_state == '':
            s.linux_extra_Button_disable.place(x=20, y=155)
            s.adb_test_close_disable.place(x=400, y=370)
        else:
            s.linux_extra_Button_disable.place_forget()
            s.linux_extra_Button.place(x=20, y=155)

        # 正常情况下开启linux模式所有功能
        s.linux_button_label.place_forget()
        s.linux_developer_mode_Button_close.place(x=200, y=190)
        s.uuid_label.place(x=20, y=310)
        s.uuid_paste.place(x=200, y=360)
        s.uuid_get.place(x=20, y=360)

        # 启动特定的绑定事件（每次连接设备仅启动一次）
        if not uuid_server_flag:
            s.uuid_get_bind()  # 自动获取设备UUID

            # 每次连接设备仅启动一次（新增每次连接Linux设备时都会检测一遍是否初始化）
            linux_main.check_init(s.init_str, s.linux_init_Button
                                  , s.linux_init_Button_disable, devices_linux_flag, s.linux_all_button_close
                                  , s.more_devices_value.get(), s.init_again_Button_disable, s.linux_type_str.get())

            uuid_server_flag = True
            linux_button_flag = False

    def version_history_frame(s):
        # 历史版本信息窗口
        s.verion_frame_full = tkinter.Frame(s.main_frame_adb, width=width, height=height)
        s.verion_frame = tkinter.Frame(s.verion_frame_full, width=width, height=height)
        s.scrollbar = tkinter.Scrollbar(s.verion_frame)
        s.version_listbox = tkinter.Listbox(s.verion_frame, width=50, height=19, yscrollcommand=(s.scrollbar.set))
        s.version_listbox.bindtags((s.version_listbox, 'all'))
        s.scrollbar.config(command=(s.version_listbox.yview))
        s.scrollbar.pack(side=(tkinter.RIGHT), fill=(tkinter.Y))
        s.version_listbox.pack()
        version_read = open(version_path, 'r', encoding='utf-8')
        for readline in version_read.readlines():
            s.version_listbox.insert(tkinter.END, readline)
        version_read.close()
        s.verion_frame.place(y=55)
        s.verion_frame_full.place(y=20)

    def back_bind(s):
        def t_back():
            s.back_button_disable.place(x=20, y=20)
            devices_SN = s.more_devices_value.get()
            quickly.android_back(devices_SN)
            s.back_button_disable.place_forget()

        t_back = threading.Thread(target=t_back)
        t_back.setDaemon(True)
        t_back.start()

    def settings_bind(s):
        def t_settings():
            s.settings_button_disable.place(x=190, y=20)
            devices_SN = s.more_devices_value.get()
            quickly.android_settings(devices_SN)
            s.settings_button_disable.place_forget()

        t_settings = threading.Thread(target=t_settings)
        t_settings.setDaemon(True)
        t_settings.start()

    def reboot_bind(s):
        def t_reboot():
            s.reboot_button_disable.place(x=20, y=60)
            s.reboot_str.set(languages_all['reboot_doing'])
            devices_SN = s.more_devices_value.get()
            state = quickly.current_reboot(devices_SN)
            # 若设备没有连接，获取的是None，则恢复正常按钮状态
            if not state:
                s.reboot_button_disable.place_forget()
            else:
                while True:
                    android_os_status = public.execute_cmd('adb -s ' + devices_SN + ' shell getprop sys.boot_completed')
                    if '1' in android_os_status:
                        s.reboot_str.set(languages_all['reboot_success'])
                        break
                time.sleep(10)
                s.reboot_button_disable.place_forget()

        t_reboot = threading.Thread(target=t_reboot)
        t_reboot.setDaemon(True)
        t_reboot.start()

    def shutdown_bind(s):
        def t_shutdown():
            s.shutdown_button_disable.place(x=190, y=60)
            devices_SN = s.more_devices_value.get()
            quickly.android_shutdown(devices_SN)
            s.shutdown_button_disable.place_forget()

        t_shutdown = threading.Thread(target=t_shutdown)
        t_shutdown.setDaemon(True)
        t_shutdown.start()

    def clear_bind(s):
        def t_clear():
            s.clear_button_disable.place(x=20, y=100)
            devices_SN = s.more_devices_value.get()
            quickly.clear_cache(devices_SN)
            s.clear_button_disable.place_forget()

        t_clear = threading.Thread(target=t_clear)
        t_clear.setDaemon(True)
        t_clear.start()

    def kill_bind(s):
        def t_kill():
            s.kill_button_disable.place(x=190, y=100)
            devices_SN = s.more_devices_value.get()
            quickly.terminate_program(devices_SN)
            s.kill_button_disable.place_forget()

        t_kill = threading.Thread(target=t_kill)
        t_kill.setDaemon(True)
        t_kill.start()

    def desktop_bind(s):
        def t_desktop():
            s.desktop_button_disable.place(x=20, y=140)
            devices_SN = s.more_devices_value.get()
            quickly.android_desktop(devices_SN)
            s.desktop_button_disable.place_forget()

        t_desktop = threading.Thread(target=t_desktop)
        t_desktop.setDaemon(True)
        t_desktop.start()

    def awake_bind(s):
        def t_awake():
            s.awake_button_disable.place(x=190, y=140)
            devices_SN = s.more_devices_value.get()
            quickly.android_awake(devices_SN)
            s.awake_button_disable.place_forget()

        t_awake = threading.Thread(target=t_awake)
        t_awake.setDaemon(True)
        t_awake.start()

    def linux_shutdown_bind(s):
        def t_linux_shutdown():
            s.linux_shutdown_button_disable.place(x=20, y=180)
            devices_SN = s.more_devices_value.get()
            quickly.linux_shutdown(devices_SN)
            s.linux_shutdown_button_disable.place_forget()

        t_linux_shutdown = threading.Thread(target=t_linux_shutdown)
        t_linux_shutdown.setDaemon(True)
        t_linux_shutdown.start()

    def copy_SN_bind(s):
        def t_copy_SN():
            s.copy_SN_button_disable.place(x=190, y=180)
            devices_state = public.device_connect()
            if not devices_state:
                tkinter.messagebox.showinfo(languages_all['copy_sn_fail_title'],languages_all['copy_sn_fail'])
            else:
                devices_SN = s.more_devices_value.get()
                quickly.current_copy_SN(devices_SN)
            s.copy_SN_button_disable.place_forget()

        t_copy_SN = threading.Thread(target=t_copy_SN)
        t_copy_SN.setDaemon(True)
        t_copy_SN.start()

    def public_mac_ip(s, devices):
        # 获取设备MAC（物理）地址
        mac_result = public.wifi_mac_result(devices)
        if mac_result.strip() == '':
            s.devices_mac_str.set(languages_all['get_mac_fail'])
            s.devices_mac.unbind('<Button-1>')
        else:
            s.devices_mac_str.set(languages_all['get_mac_message'] + mac_result.strip())
            s.devices_mac.bind('<Button-1>', lambda x: public.pyperclip_copy_paste(mac_result))
        # 获取设备ip地址
        ip_result = public.devices_ip_result(devices)
        if ip_result.strip() == '':
            s.devices_ip_str.set(languages_all['get_mac_fail'])
            s.devices_ip.unbind('<Button-1>')
        else:
            s.devices_ip_str.set(languages_all['get_ip_message'] + ip_result.strip())
            s.devices_ip.bind('<Button-1>', lambda x: public.pyperclip_copy_paste(ip_result))

    def get_linux_sn(s,sn,devices):
        # 获取SN号主要逻辑
        sn_re = re.findall('"sn":(.*?)}', sn)
        # print(sn_re)
        try:
            sn_result = eval(sn_re[0])
        except Exception:
            # 如果识别错误就使用另一个提取方式
            sn_result = eval(sn_re[-1].strip().split(',')[-1])
        # 判断序列号是否只含有字母或数字，如果有特殊字符就返回False，否则返回True
        string_sn = sn_result.isalnum()
        # print(string_sn)
        if not string_sn:
            sn_result = ''
        else:
            with open(linux_sn_path, 'w') as fp:
                fp.write(sn_result)
            # 上传到设备里面方便保存读取
            public.execute_cmd('adb -s ' + devices + ' push ' + linux_sn_path + ' /data/linux_sn.ini')
        if sn_result.strip() == '':
            s.devices_sn_str.set(languages_all['get_sn_again'])
            s.devices_sn.unbind('<Button-1>')
            public.execute_cmd('adb -s ' + devices + ' shell rm -rf /data/linux_sn.ini')
        else:
            if len(sn_result.strip()) > 15:
                s.devices_sn_str.set('设备序列号：序列号过长直接单击复制')
                s.devices_sn.bind('<Button-1>', lambda x: public.pyperclip_copy_paste(sn_result.strip()))
            else:
                sn = public.linux_sn_cmd('adb -s ' + devices + ' shell grep "sn" /data/syslog.log')
                sn_re = re.findall('"sn":(.*?)}', sn)
                sn_result_new = eval(sn_re[0])
                if sn_result != sn_result_new:
                    with open(linux_sn_path, 'w') as fp:
                        fp.write(sn_result)
                    # 上传到设备里面方便保存读取
                    public.execute_cmd(
                        'adb -s ' + devices + ' push ' + linux_sn_path + ' /data/linux_sn.ini')
                    s.devices_sn_str.set(languages_all['get_sn_message'] + sn_result_new.strip())
                    s.devices_sn.bind('<Button-1>', lambda x: public.pyperclip_copy_paste(sn_result))
                else:
                    s.devices_sn_str.set(languages_all['get_sn_message'] + sn_result.strip())
                    s.devices_sn.bind('<Button-1>', lambda x: public.pyperclip_copy_paste(sn_result))

    def linux_sn_number(s, devices):
        # Linux SN号 获取方式
        devices_sn = public.execute_cmd('adb -s ' + devices + ' shell cat /data/linux_sn.ini')
        devices_sn_finally = ' '.join(devices_sn.strip().split()).split(':')[-1]
        if devices_sn_finally.strip() == 'No such file or directory':
            # 从设备系统日志中过滤出SN
            sn = public.linux_sn_cmd('adb -s ' + devices + ' shell grep "sn" /data/syslog.log')
            # print('测试：' + sn)
            if sn.strip() == '':
                s.devices_sn_str.set(languages_all['get_sn_check'])
                s.devices_sn.unbind('<Button-1>')
            else:
                try:
                    s.get_linux_sn(sn,devices)
                except (IndexError, SyntaxError):
                    s.devices_sn_str.set(languages_all['get_sn_again_check'])
                    s.devices_sn.unbind('<Button-1>')
        else:
            sn_result = public.execute_cmd('adb -s ' + devices + ' shell cat /data/linux_sn.ini')
            if sn_result.strip() == '':
                s.devices_sn_str.set(languages_all['get_sn_no'])
                s.devices_sn.unbind('<Button-1>')
                public.execute_cmd('adb -s ' + devices + ' shell rm -rf /data/linux_sn.ini')
            else:
                if len(sn_result.strip()) > 15:
                    s.devices_sn_str.set('设备序列号：序列号过长直接单击复制')
                    s.devices_sn.bind('<Button-1>', lambda x: public.pyperclip_copy_paste(sn_result.strip()))
                else:
                    s.devices_sn_str.set(languages_all['get_sn_message'] + sn_result.strip())
                    s.devices_sn.bind('<Button-1>', lambda x: public.pyperclip_copy_paste(sn_result))

    def devices_bind(s):
        def moving_radio_set():
            if s.moving_str.get() == 0:
                # 隐藏非选中的frame
                try:
                    s.moving_software_info_frame.place_forget()
                except AttributeError:
                    pass
                # 显示选中的frame
                s.moving_device_frame1.place(x=375, y=115)
            elif s.moving_str.get() == 1:
                # 隐藏非选中的frame
                s.moving_device_frame1.place_forget()
                # 显示选中的frame
                s.moving_software_info_frame.place(x=375, y=115)

        def moving_devices():
            # 恢复被隐藏的label
            s.software_version.place(x=0, y=150)

            s.devices_null.set(languages_all['devices_null'])
            s.devices_type_error.set(languages_all['devices_null'])
            s.devices_mode_str.set(languages_all['moving_devices_state'])
            # 取消事件绑定
            s.devices_sn.unbind('<Button-1>')
            s.devices_mac.unbind('<Button-1>')
            s.devices_ip.unbind('<Button-1>')
            s.android_version.unbind('<Button-1>')
            # 还原提示
            s.devices_sn_str.set(languages_all['android_devices_SN'])
            s.devices_mac_str.set(languages_all['moving_devices_mac'])
            s.devices_ip_str.set(languages_all['moving_devices_ip'])
            s.android_version_str.set(languages_all['moving_devices_android_platform'])
            s.software_version_str.set(languages_all['moving_devices_android_version'])
            s.firmware_version_str.set(languages_all['moving_devices_android_firmware'])

        def t_update_status():
            global software_version_flag
            time.sleep(3)  # 延时3S，等待Linux类型显示出来
            while True:
                time.sleep(1)
                try:
                    s.my_logo_label_warning.place_forget()  # 确保加载完毕就一定隐藏提示
                except AttributeError:
                    pass
                try:
                    # 实时检测设备所有信息
                    devices = s.more_devices_value.get()

                    if not public.device_connect():
                        pass
                    else:
                        # 更新设备类型
                        if s.devices_type_str.get() == languages_all['devices_type_android_2']:
                            s.devices_mode_str.set(languages_all['devices_type_android'])
                            # 更新设备序列号（安卓）
                            # 更换更加准确查询序列号的命令
                            sn_result = public.execute_cmd('adb -s ' + devices + ' shell getprop gsm.serial')
                            if sn_result.strip() == '' or ' ' in sn_result.strip():
                                sn_result = public.execute_cmd('adb -s ' + devices + ' shell getprop ro.serialno')
                            if len(sn_result) > 19:
                                s.devices_sn_str.set(languages_all['devices_sn_1'] + sn_result.strip())
                            else:
                                s.devices_sn_str.set(languages_all['get_sn_message'] + sn_result.strip())
                            s.devices_sn.bind('<Button-1>', lambda x: public.pyperclip_copy_paste(sn_result.strip()))
                            s.public_mac_ip(devices)
                            # 获取安卓版本号
                            try:
                                android_version = public.execute_cmd(
                                    'adb -s ' + devices + ' shell getprop ro.build.version.release')
                                s.android_version_str.set(languages_all['devices_android_version'] + android_version.strip())
                            except TypeError:
                                pass
                            # 显示安卓的应用版本号label
                            s.software_version.place(x=0, y=150)
                            # 获取安卓的应用版本号和固件版本号
                            try:
                                software_version = public.android_software_version_result(devices)
                                s.software_version_str.set(languages_all['devices_android_software'] + software_version)
                            except TypeError:
                                pass
                            firmware_version = public.android_firmware_version_result(devices)
                            try:
                                s.firmware_version_str.set(languages_all['devices_android_fireware'] + firmware_version)
                            except TypeError:
                                pass
                        elif s.devices_type_str.get() == 'Linux':
                            s.devices_mode_str.set(languages_all['devices_type_linux'])
                            s.linux_sn_number(devices)
                            s.public_mac_ip(devices)
                            # 更换安卓系统版本 --》 Linux设备UUID
                            # uuid_get_result = public.execute_cmd('adb -s ' + device_SN + ' shell ls -lh /data/UUID.ini')
                            # uuid_get_result_finally = ' '.join(uuid_get_result.split()).split(':')[-1]
                            # agOsUUID_result = public.execute_cmd('adb -s ' + device_SN + ' shell ls -lh /data/agOsUUID.txt')
                            # agOsUUID_result_finally = ' '.join(agOsUUID_result.split()).split(':')[-1]
                            if s.devices_type_str.get() == 'Linux':
                                # 隐藏安卓的应用版本号label
                                s.software_version.place_forget()
                            else:
                                # 显示安卓的应用版本号label
                                s.software_version.place(x=0, y=150)
                            uuid = public.execute_cmd('adb -s ' + devices + ' shell ag_os')
                            uuid_re = re.findall('uuid:(.*?)\\n', uuid)
                            uuid_result = ''.join(uuid_re).strip()
                            if uuid_result == '':
                                s.android_version_str.set(languages_all['devices_write_sn_null'])
                                s.android_version.unbind('<Button-1>')
                            else:
                                s.android_version_str.set(languages_all['devices_get_uuid'] + uuid_result)
                                s.android_version.bind('<Button-1>', lambda x: public.pyperclip_copy_paste(uuid_result))
                            version = public.execute_cmd('adb -s ' + devices + ' shell ag_os')
                            genie_re = re.findall('genie version:(.*?)\\n', version)
                            firmware_re = re.findall('firmware version:(.*?)\\n', version)
                            genie_version = ''.join(genie_re).strip()
                            firmware_version = ''.join(firmware_re).strip()
                            if genie_version == '' or firmware_version == '':
                                s.firmware_version_str.set(languages_all['devices_write_sn_null_2'])
                                s.firmware_version.unbind('<Button-1>')
                            else:
                                s.firmware_version_str.set(languages_all['software_version'] + genie_version.strip() + '\n'
                                                           + languages_all['firmware_version'] + firmware_version.strip())
                                s.firmware_version.bind('<Button-1>', lambda x: public.pyperclip_copy_paste(
                                    languages_all['software_version'] + genie_version.strip() + '\n'
                                    + languages_all['firmware_version'] + firmware_version.strip()))
                except AttributeError:
                    pass
                time.sleep(3)

        def devices_type():
            # try:
            #     s.devices_type_str.set('正在检测设备类型...')
            # except AttributeError:
            #     pass
            # 设置停顿时间防止线程阻塞
            # time.sleep(2)
            # 检测设备类型
            global devices_linux_flag
            adb_install_state = open(adb_upgrade_flag, 'r').read()
            # conflict_software_flag = public.find_pid_name(conflict_software_list)
            if adb_install_state.strip() == 'ADB upgrade':
                print('ADB正在升级2....')
            else:
                # if conflict_software_flag:
                #     # print('测试是否屏蔽 - 检测设备类型')
                #     pass
                # else:
                # print('正在检测设备类型 -----------')
                try:
                    time.sleep(2)  # 延时2S等待设备序列号加载出来
                    device_SN = s.more_devices_value.get()
                    device_type = public.device_type_android(device_SN)
                    # print(device_type.strip())  # 调试Logs
                    # 增加strip方法，去掉结果的两边空格以便进行识别
                    if device_type.strip() == 'Android':
                        s.devices_type_str.set(languages_all['devices_type_android_2'])
                        devices_linux_flag = False
                        with open(devices_type_log, 'w') as fp:
                            fp.write(device_type.strip())
                        fp.close()
                        # print('安卓')
                    elif device_type.strip() == '/bin/sh: getprop: not found' or device_type.strip() == 'adb.exe: unknown command getprop':
                        # Linux无法使用adb shell getprop命令
                        device_type_linux = public.execute_cmd('adb -s ' + device_SN + ' shell cat /proc/version')
                        device_type_linux_finally = device_type_linux.split(' ')[0]
                        # print(device_type_linux)  # 调试Logs
                        if device_type_linux_finally == 'Linux':
                            s.devices_type_str.set('Linux')
                            devices_linux_flag = True
                            with open(devices_type_log, 'w') as fp:
                                fp.write(device_type.strip())
                            fp.close()
                            # print('Linux')
                        else:
                            s.devices_type_str.set(languages_all['devices_type_null'])
                            # print('未知设备')
                except AttributeError:
                    print('出现AttributeError无影响，请忽略')
                    pass

        def t_more_devices():
            global adb_server_all_flag, lower_CPU_utility
            devices_current_flag = False
            # 多设备连接匹配
            while True:
                if not adb_server_all_flag:
                    break
                else:
                    adb_install_state = open(adb_upgrade_flag, 'r').read()
                    # conflict_software_flag = public.find_pid_name(conflict_software_list)
                    if adb_install_state.strip() == 'ADB upgrade':
                        s.more_devices_list = [languages_all['adb_upgrade_no']]
                        s.more_devices_combobox['value'] = s.more_devices_list
                        s.more_devices_combobox.current(0)
                        print('ADB升级中3...')
                    else:
                        devices_list = public.device_connect()
                        # print(devices_list)
                        if not devices_list and not lower_CPU_utility:
                            s.more_devices_list = [languages_all['devices_get_null']]
                            s.more_devices_combobox['value'] = s.more_devices_list
                            s.more_devices_combobox.current(0)
                            devices_current_flag = False
                            lower_CPU_utility = True
                            continue
                        elif s.more_devices_value.get().strip() == 'List of':
                            print(s.more_devices_list)
                            print('删除异常List of...')
                            try:
                                index = s.more_devices_list.index('List of')
                                print('异常数据索引 ：' + str(index))
                                s.more_devices_list.pop(index)  # 删除“List of”异常元素
                            except ValueError:
                                pass
                            s.more_devices_list = public.device_connect()
                            # print('测试1：{}'.format(s.more_devices_list))
                            s.more_devices_combobox['value'] = s.more_devices_list
                            try:
                                s.more_devices_combobox.current(0)
                            except tkinter.TclError:
                                print('出现TclError，忽略即可！！！')
                            continue
                        elif s.more_devices_value.get().strip() not in devices_list and \
                                s.more_devices_value.get().strip() != languages_all['devices_get_null'] \
                                and s.more_devices_value.get().strip() != '':
                            s.more_devices_list = devices_list
                            s.more_devices_combobox['value'] = s.more_devices_list
                            try:
                                s.more_devices_combobox.current(0)
                            except (tkinter.TclError,Exception):
                                continue
                        else:
                            s.more_devices_list = devices_list
                            s.more_devices_combobox['value'] = s.more_devices_list
                            # 保存设备序列号以便后面功能使用，实时同步
                            with open(devices_log, 'w') as fp:
                                fp.write(s.more_devices_value.get())
                            fp.close()
                            if not devices_current_flag:
                                # 首次连接设备后只匹配首个序列号一次
                                devices_list = public.device_connect()
                                if devices_list:
                                    try:
                                        s.more_devices_combobox.current(0)
                                        devices_current_flag = True
                                    except tkinter.TclError:
                                        pass
                            lower_CPU_utility = False
                time.sleep(2)

        @adb_tools_log
        def t_devices():
            global adb_server_flag, conflict_model_flag, adb_server_all_flag, lower_CPU_utility_connect, \
                lower_CPU_utility_disconnect, linux_Initialize_flag
            s.devices_str.set(languages_all['devices_connect_state'])
            lower_CPU_utility_connect = False
            lower_CPU_utility_disconnect = False
            while True:
                if not adb_server_all_flag:
                    break
                else:
                    # 显示动态单选frame
                    try:
                        moving_radio_set()
                    except AttributeError:
                        pass
                    adb_install_state = open(adb_upgrade_flag, 'r').read()
                    conflict_software_flag = public.find_pid_name(conflict_software_list)
                    conflict_software_name = open(conflict_software_path, 'r').read()
                    # print('冲突软件标志：' + str(conflict_software_flag))
                    # print(conflict_software_name)
                    if conflict_software_flag:
                        # 强制关闭冲突软件
                        public.execute_cmd('taskkill /F /IM %s ' % conflict_software_name + ' /T')
                        # 重要提示需要置顶
                        s.root.wm_attributes('-topmost', 1)
                        if tkinter.messagebox.askokcancel(languages_all['conflict_title'], languages_all['conflict_software_checked'] + conflict_software_name + languages_all['conflict_software_content']):
                            # 取消置顶
                            s.root.wm_attributes('-topmost', 0)
                            # my_pid = os.getpid()
                            # os.kill(my_pid, signal.SIGINT)
                            s.adb_close()  # 退出ADB测试工具
                        # 取消置顶
                        s.root.wm_attributes('-topmost', 0)
                    else:
                        # if adb_server_flag:
                        #     adb_server_flag = False
                        if adb_install_state.strip() == 'ADB upgrade':
                            print('ADB正在升级1....')
                            s.devices_fail.place_forget()
                            s.devices_type_fail.place_forget()
                            s.devices_type_success.place(x=325, y=425)
                            s.devices_success.place(x=450, y=0)
                            s.devices_str.set(languages_all['adb_upgrade_doing'])
                            s.devices_type_str.set(languages_all['adb_upgrade_doing'])
                        else:
                            devices_finally = public.device_connect()
                            # print('检测设备连接状态 === ' + str(devices_finally))
                            if not devices_finally:
                                # 动态设备参数调整
                                moving_devices()
                                if not lower_CPU_utility_disconnect:
                                    print('已断开连接！')
                                    s.devices_fail.place(x=470, y=0)
                                    s.devices_type_fail.place(x=325, y=425)
                                    s.devices_success.place_forget()
                                    s.devices_type_success.place_forget()
                                    # 确保切换设备类型时Linux相关功能按钮不会主动显示出来
                                    try:
                                        s.linux_all_button_close()
                                    except AttributeError:
                                        pass
                                    lower_CPU_utility_disconnect = True
                                    # lower_CPU_utility_connect = False
                                    linux_Initialize_flag = False
                            else:
                                # if not lower_CPU_utility_connect:
                                # print('已连接设备！')
                                # print('成功检测设备 ++++++ ')
                                s.devices_fail.place_forget()
                                s.devices_type_fail.place_forget()
                                s.devices_success.place(x=450, y=0)
                                s.devices_type_success.place(x=325, y=425)
                                for devices in devices_finally:
                                    if len(devices_finally) == 1:
                                        if len(devices) > 15:
                                            # 超过长度限制用...表示
                                            s.devices_str.set(devices[:10] + languages_all['devices_connect_exceed'])
                                        else:
                                            s.devices_str.set(devices + languages_all['devices_connect_no_exceed'])
                                        continue
                                    elif len(devices_finally) > 1:
                                        s.devices_str.set(languages_all['devices_connect_more'])
                                        continue
                                devices_type()  # 调用检测设备类型
                                # lower_CPU_utility_connect = True
                                lower_CPU_utility_disconnect = False
                            # 非Linux模式终止循环
                            try:
                                adb_model = open(adb_model_text,'r').read()
                                if adb_model.strip() != 'linux':
                                    public.stop_thread(s.t_linux_button)
                                    # print('已终止Linux模式线程循环！')
                            except Exception:
                                pass
                time.sleep(3)

        t_devices = threading.Thread(target=t_devices)
        t_devices.setDaemon(True)
        t_devices.start()

        t_more_devices = threading.Thread(target=t_more_devices)
        t_more_devices.setDaemon(True)
        t_more_devices.start()

        t_update_status = threading.Thread(target=t_update_status)
        t_update_status.setDaemon(True)
        t_update_status.start()

    def adb_install_main(s):
        shutil.copy(adb_path, make_dir)
        # 解压
        zip_path = make_dir + 'adb-tools.zip'
        public.zip_extract(zip_path, make_dir)
        # 清理压缩包
        os.remove(zip_path)
        # 配置环境变量
        environ_list = os.environ["PATH"]
        if adb_tools_path not in environ_list:  # 避免重复添加导致环境变量导致系统环境变量错乱
            public.temporary_environ(adb_tools_path)
            public.permanent_environ(adb_tools_path)
        else:
            print('已设置环境变量，升级过程中无需重复添加！')
        # 打印测试
        print(public.execute_cmd('adb version'))

    def adb_bind(s):
        # 检测ADB服务状态
        @adb_tools_log
        def adb_upgrade_called():
            # ADB升级自主取消逻辑
            adb_version_new = int(open(adb_version_path, 'r').read())
            adb_new_version_str = open(adb_new_version, 'r').read()
            print('用户已自主取消升级！')
            adb_upgrade_button = tkinter.Button(s.main_frame_adb, text=languages_all['adb_upgrade_button'])
            adb_upgrade_button.bind('<Button-1>', lambda x:s.adb_upgrade_bind(adb_version_new,adb_new_version_str,adb_upgrade_button))
            adb_upgrade_button.place(x=210, y=418)

        @adb_tools_log
        def adb_install_upgrade():
            global lower_CPU_utility_disconnect
            if not os.path.exists(adb_tools_path):
                s.adb_install_main()
            else:
                # ADB调试桥版本升级
                adb_version_new = int(open(adb_version_path, 'r').read())
                adb_new_version_str = open(adb_new_version, 'r').read()
                adb_state = open(adb_upgrade_flag, 'r').read()
                print(adb_version_new)
                adb_version = int(public.adb_version())
                print('当前ADB版本号：' + str(adb_version))
                if adb_version < adb_version_new and adb_state.strip() == '':
                    upgrade_content = languages_all['adb_upgrade_content']
                    if tkinter.messagebox.askokcancel(languages_all['adb_upgrade_confirm'],upgrade_content.format(adb_new_version_str)):
                        # 升级启动状态
                        with open(adb_upgrade_flag, 'w') as fp:
                            fp.write('ADB upgrade')
                        s.adb_str.set(languages_all['adb_upgrade_message'])
                        # 需要时间停掉所有ADB的行为
                        adb_pid = public.get_pid('adb.exe')
                        with open(log_path,'a+') as fp:
                            fp.write('adb.exe的pid为{}\n'.format(adb_pid))
                        public.execute_cmd('adb kill-server')  # 关闭ADB服务
                        public.execute_cmd('taskkill /F /IM %s ' % 'cmd.exe /T')  # 结束cmd窗口以免占用adb-tools文件
                        public.execute_cmd('del /F /A /Q ' + adb_tools_path)
                        # 下面再执行一次确保进程不在
                        time.sleep(2)
                        os.popen('adb kill-server', 'r')
                        os.popen('taskkill /F /IM %s ' % 'cmd.exe /T', 'r')
                        os.popen('del /F /A /Q ' + adb_tools_path,'r')
                        time.sleep(5)
                        try:
                            shutil.rmtree(adb_tools_path)  # 删除旧版本ADB文件
                            # os.remove(adb_tools_path)  # 删除旧版本ADB文件
                        except FileNotFoundError:
                            print('没有该文件无需删除！！！')
                        s.adb_install_main()

                        # 版本号格式处理
                        adb_version_list = []
                        adb_version_new_finally = '.'.join(str(adb_version_new)).split('.')
                        i = 1
                        for adb_version in adb_version_new_finally:
                            if i <= 2:
                                adb_version += '.'
                                adb_version_list.append(adb_version)
                            else:
                                adb_version = adb_version
                                adb_version_list.append(adb_version)
                            i += 1

                        adb_version_finally = ''.join(adb_version_list)
                        s.adb_str.set(languages_all['adb_upgrade_success'] + adb_version_finally)
                        print('ADB升级已完成！')
                        # 升级完成状态
                        with open(adb_upgrade_flag, 'w') as fp:
                            fp.write('ADB upgrade is complete')
                        fp.close()
                        lower_CPU_utility_disconnect = False
                        time.sleep(3)
                    else:
                        # ADB升级被用户自主取消，以后取消
                        with open(adb_upgrade_flag, 'w') as fp:
                            fp.write('ADB upgrades have been voluntarily cancelled')
                        adb_upgrade_called()
                else:
                    pass

        @adb_tools_log
        def t_adb():
            global adb_server_all_flag,adb_service_flag
            if not adb_service_flag:
                time.sleep(5)  # 等待ADB服务启动完毕
                adb_service_flag = True
            while True:
                if not adb_server_all_flag:
                    break
                else:
                    if not os.path.exists(adb_upgrade_flag):
                        with open(adb_upgrade_flag, 'w') as fp:
                            fp.write('')
                    # 中文状态下
                    adb_upgrade_state = open(adb_upgrade_flag,'r').read()
                    adb_finally = public.adb_connect()[1]
                    with open(log_path, 'w') as fp:
                        fp.write('工具已成功启动，正在打印日志中...\n')
                        fp.write('中文状态下:' + adb_finally + '\n')
                    fp.close()
                    print('中文状态下:' + adb_finally)
                    try:
                        try:
                            # 英文状态下
                            adb_english = ' '.join(public.adb_connect()).split(',')[1]
                            print('英文状态下:' + adb_english)
                            if adb_english.strip() == 'operable program or batch file.':
                                s.adb_str.set(languages_all['adb_configuration_doing'])
                                adb_install_upgrade()
                                s.adb_str.set(languages_all['adb_configuration_success'])
                                time.sleep(3)
                                s.adb_str.set(languages_all['adb_configuration_finally'])
                                if adb_upgrade_state.strip() == 'ADB upgrades have been voluntarily cancelled':
                                    adb_upgrade_called()
                                break
                        except Exception:
                            pass
                        if adb_finally.strip() == '不是内部或外部命令，也不是可运行的程序':
                            # os.chdir(adb_path)
                            # s.adb_str.set('内置ADB已开启！')
                            s.adb_str.set(languages_all['adb_configuration_doing'])
                            adb_install_upgrade()
                            s.adb_str.set(languages_all['adb_configuration_success'])
                            time.sleep(3)
                            s.adb_str.set(languages_all['adb_configuration_finally'])
                            if adb_upgrade_state.strip() == 'ADB upgrades have been voluntarily cancelled':
                                adb_upgrade_called()
                            break
                        else:
                            adb_install_upgrade()  # 用于ADB升级
                            s.adb_str.set(languages_all['adb_configuration_finally'])
                            if adb_upgrade_state.strip() == 'ADB upgrades have been voluntarily cancelled':
                                adb_upgrade_called()
                            print(public.execute_cmd('adb version'))
                            break
                    except Exception:
                        print('IndexError异常，无影响！')
                        if adb_finally == '不是内部或外部命令，也不是可运行的程序':
                            # os.chdir(adb_path)
                            # s.adb_str.set('内置ADB已开启！')
                            s.adb_str.set(languages_all['adb_configuration_doing'])
                            adb_install_upgrade()
                            s.adb_str.set(languages_all['adb_configuration_success'])
                            time.sleep(3)
                            s.adb_str.set(languages_all['adb_configuration_finally'])
                            if adb_upgrade_state.strip() == 'ADB upgrades have been voluntarily cancelled':
                                adb_upgrade_called()
                            break
                        else:
                            adb_install_upgrade()  # 用于ADB升级
                            with open(log_path, 'a+') as fp:
                                fp.write('已检测升级机制完毕\n')
                            fp.close()
                            s.adb_str.set(languages_all['adb_configuration_finally'])
                            if adb_upgrade_state.strip() == 'ADB upgrades have been voluntarily cancelled':
                                adb_upgrade_called()
                            print(public.execute_cmd('adb version'))
                            break

        t_adb = threading.Thread(target=t_adb)
        t_adb.setDaemon(True)
        t_adb.start()

    def adb_upgrade_bind(s,adb_version_new, adb_new_version_str, adb_upgrade_button):
        def t_adb_upgrade_bind():
            global lower_CPU_utility_disconnect
            adb_version = int(public.adb_version())
            if adb_version < adb_version_new:
                upgrade_content = languages_all['adb_upgrade_content']
                if tkinter.messagebox.askokcancel(languages_all['adb_upgrade_confirm'], upgrade_content.format(adb_new_version_str)):
                    adb_upgrade_button.place_forget()
                    # 升级启动状态
                    with open(adb_upgrade_flag, 'w') as fp:
                        fp.write('ADB upgrade')
                    s.adb_str.set(languages_all['adb_upgrade_message'])
                    # 需要时间停掉所有ADB的行为
                    adb_pid = public.get_pid('adb.exe')
                    with open(log_path, 'a+') as fp:
                        fp.write('adb.exe的pid为{}\n'.format(adb_pid))
                    public.execute_cmd('adb kill-server')  # 关闭ADB服务
                    public.execute_cmd('taskkill /F /IM %s ' % 'cmd.exe /T')  # 结束cmd窗口以免占用adb-tools文件
                    public.execute_cmd('del /F /A /Q ' + adb_tools_path)
                    # 下面再执行一次确保进程不在
                    time.sleep(2)
                    os.popen('adb kill-server', 'r')
                    os.popen('taskkill /F /IM %s ' % 'cmd.exe /T', 'r')
                    os.popen('del /F /A /Q ' + adb_tools_path, 'r')
                    time.sleep(5)
                    try:
                        shutil.rmtree(adb_tools_path)  # 删除旧版本ADB文件
                        # os.remove(adb_tools_path)  # 删除旧版本ADB文件
                    except FileNotFoundError:
                        print('没有该文件无需删除！！！')
                    s.adb_install_main()

                    # 版本号格式处理
                    adb_version_list = []
                    adb_version_new_finally = '.'.join(str(adb_version_new)).split('.')
                    i = 1
                    for adb_version in adb_version_new_finally:
                        if i <= 2:
                            adb_version += '.'
                            adb_version_list.append(adb_version)
                        else:
                            adb_version = adb_version
                            adb_version_list.append(adb_version)
                        i += 1

                    adb_version_finally = ''.join(adb_version_list)
                    s.adb_str.set(languages_all['adb_upgrade_success'] + adb_version_finally)
                    print('ADB升级已完成！')
                    # 升级完成状态
                    with open(adb_upgrade_flag, 'w') as fp:
                        fp.write('ADB upgrade is complete')
                    fp.close()
                    lower_CPU_utility_disconnect = False

        t_adb_upgrade_bind = threading.Thread(target=t_adb_upgrade_bind)
        t_adb_upgrade_bind.setDaemon(True)
        t_adb_upgrade_bind.start()

    def main_screenshot(s, touch_name):
        # 截图功能核心逻辑代码
        devices_SN = s.more_devices_value.get()
        screenshot_success = screen_record.main_screenshots(touch_name, devices_SN)
        s.screen_str.set(screenshot_success)

    def screenshot_bind(s):
        def t_screenshot():
            s.screen_button_disable.place(x=20, y=140)
            devices_state = public.device_connect()
            touch_name = s.screen_entry.get()
            s.screen_str.set(languages_all['screen_doing'])
            # 截图文件名长度检测
            if len(touch_name) <= 8:
                # 检测安卓系统是否完全启动，未完全启动时设备本地sdcard没显示，则提示处理；正常显示后则启动截图
                if not devices_state:
                    s.screen_str.set(languages_all['record_connect_null'])
                else:
                    # 创建临时文件
                    devices_SN = s.more_devices_value.get()
                    make_state = screen_record.cd_screenshots(devices_SN)
                    if make_state == 'Non-Android Devices':
                        s.screen_str.set(languages_all['record_type_error'])
                    else:
                        if not make_state:
                            s.main_screenshot(touch_name)
                        else:
                            make_state_finally = make_state.split(':')[-1]
                            print(make_state_finally)
                            if make_state_finally == ' No such file or directory\r\n':
                                s.screen_str.set(languages_all['record_system_start_error'])
                            else:
                                s.main_screenshot(touch_name)
            else:
                s.screen_str.set(languages_all['record_name_long'])
            s.screen_button_disable.place_forget()

        t_screenshot = threading.Thread(target=t_screenshot)
        t_screenshot.setDaemon(True)
        t_screenshot.start()

    def open_screen_bind(s):
        def open_screen():
            s.open_screen_button_disable.place(x=200, y=140)
            screen_record.open_screenshots()
            s.open_screen_button_disable.place_forget()

        open_screen = threading.Thread(target=open_screen)
        open_screen.setDaemon(True)
        open_screen.start()

    def record_stop_bind(s):
        # 停止录屏标志
        s.record_stop_button_disable.place(x=200, y=330)
        with open(record_state, 'w') as fp:
            fp.write('Stop recording screen')
        fp.close()
        with open(record_screen_state, 'w') as fp:
            fp.write('Stop recording screen')
        fp.close()

    def record_bind(s):
        def t_record():
            # 录屏运行
            global record_stop_flag
            s.record_stop_button_disable.place_forget()
            s.record_button_disable.place(x=20, y=330)
            s.record_stop_button.place(x=200, y=330)
            s.reset_button_disable.place(x=200, y=370)
            devices_state = public.device_connect()
            s.record_str.set(languages_all['record_starting'])
            if not devices_state:
                s.record_str.set(languages_all['record_connect_null2'])
                # 按钮复原
                s.record_button_disable.place_forget()
                s.record_stop_button_disable.place(x=200, y=330)
                s.reset_button_disable.place_forget()
            else:
                # 记录录屏模式
                s.record_model_selected = s.record_model_str.get()
                print('录屏模式：' + str(s.record_model_selected))
                with open(record_model_log, 'w') as fp:
                    fp.write(str(s.record_model_selected))
                fp.close()

                # 获取录屏时间
                s.record_time_get = s.record_time.get()
                s.record_time_re = re.findall('(.*?)' + languages_all['record_seconds'], s.record_time_get)
                s.record_time_selected = ''.join(s.record_time_re)

                with open(record_stop_config, 'w') as fp:
                    fp.write('0')
                fp.close()
                # 获取录屏名称
                s.record_name = s.record_entry.get()
                # with open(record_name,'w') as fp:
                #     fp.write(s.record_name)
                devices_SN = s.more_devices_value.get()
                screen_record.record(s.record_name, s.record_time_selected, str(s.record_model_selected), devices_SN)

        def record_time():
            # 显示录屏状态
            devices_state = public.device_connect()
            if not devices_state:
                pass
            else:
                with open(record_state, 'w') as fp:
                    fp.write('')
                fp.close()
                # record_end_finally = screen_record.record_time(s.record_str)
                screen_record.record_time(s.record_str)
                record_model_get = open(record_model_log, 'r').read()
                record_state_finally = open(record_screen_state, 'r').read()
                if record_model_get == '0':
                    if record_state_finally == 'Non-Android Devices':
                        pass
                    else:
                        s.record_str.set(languages_all['record_save_file'])
                        # s.record_name = open(record_name,'r').read()
                        s.record_name = s.record_entry.get()
                        devices_SN = s.more_devices_value.get()
                        screen_record.record_pull(s.record_name, record_model_get, devices_SN)
                        time.sleep(3)  # 延迟3S同步状态
                        s.record_str.set(languages_all['record_save_success'])
                elif record_model_get == '1':
                    # # 返回原始地址，防止与本地ADB服务发生冲突导致无法使用
                    # original_path = open(exe_path, 'r').read()
                    # os.chdir(original_path)
                    #
                    # # 关闭ADB服务，以免影响本地ADB服务的开启
                    # public.execute_cmd('adb kill-server')

                    if record_state_finally == 'Non-Android Devices':
                        pass
                    else:
                        # 连续模式计数
                        r = int(open(record_count, 'r').read())
                        r += 1
                        with open(record_count, 'w') as fp:
                            fp.write(str(r))
                        fp.close()
                        s.record_str.set(languages_all['record_save_doing'])
                        s.record_name = s.record_entry.get()
                        devices_SN = s.more_devices_value.get()
                        screen_record.record_pull(s.record_name, record_model_get, devices_SN)
                        time.sleep(3)  # 延迟3S同步状态
                        s.record_str.set(languages_all['record_save_success_2'])
                s.record_button_disable.place_forget()
                s.record_stop_button_disable.place(x=200, y=330)
                s.reset_button_disable.place_forget()

        def record_stop():
            # 录屏停止机制
            global record_stop_flag
            record_stop_flag = False
            with open(record_screen_state, 'w') as fp:
                fp.write('')
            fp.close()
            with open(record_stop_config, 'w') as fp:
                fp.write('')
            fp.close()
            while True:
                record_device = public.device_connect()
                record_stop_state = open(record_screen_state, 'r').read()
                record_stop_ini = open(record_stop_config, 'r').read()
                if record_stop_state == 'Stop recording screen' and record_stop_ini == '0':
                    # os.popen('taskkill /F /IM %s ' % 'adb.exe /T', 'r')
                    # os.popen('taskkill /F /IM %s ' % 'record_main.exe /T', 'r')
                    try:
                        public.stop_thread(t_record)
                        public.stop_thread(record_time)
                    except ValueError:
                        pass
                    s.record_button_disable.place_forget()
                    s.record_stop_button_disable.place(x=200, y=330)
                    s.reset_button_disable.place_forget()
                    s.record_str.set(languages_all['record_terminate'])
                    break
                elif record_stop_state == 'Stop recording screen' and record_stop_ini == '1':
                    # os.popen('taskkill /F /IM %s ' % 'record_main.exe /T', 'r')
                    # 通过关闭并重启ADB达到录屏命令的自动断开，以便自动生成录屏文件
                    print('正在断开并重启ADB服务...')
                    devices_SN = s.more_devices_value.get()
                    # 关闭ADB服务
                    public.execute_cmd('adb -s ' + devices_SN + ' kill-server')
                    # 重启ADB服务
                    public.execute_cmd('adb -s ' + devices_SN + ' start-server')
                    print('ADB服务重启成功！！！')
                    try:
                        # 连续模式停止
                        public.stop_thread(t_record)
                        print('主动中断连续模式！！！')
                    except ValueError:
                        print('手动模式无需强制中断线程---')
                        pass
                    # 等待文件保存完毕或ADB服务完全启动再复原按钮
                    time.sleep(7)
                    s.record_button_disable.place_forget()
                    s.record_stop_button_disable.place(x=200, y=330)
                    s.reset_button_disable.place_forget()
                    break
                elif not record_device and record_stop_ini == '0':
                    # 未录屏前断开设备
                    # os.popen('taskkill /F /IM %s ' % 'record_main.exe /T', 'r')
                    s.record_str.set(languages_all['record_terminate_2'])
                    s.record_button_disable.place_forget()
                    s.record_stop_button_disable.place(x=200, y=330)
                    s.reset_button_disable.place_forget()
                    break
                elif record_stop_state == 'Non-Android Devices':
                    print('检测到非安卓设备，无法正常录屏')
                    s.record_str.set(languages_all['record_type_error'])
                    s.record_button_disable.place_forget()
                    s.record_stop_button_disable.place(x=200, y=330)
                    s.reset_button_disable.place_forget()
                    break

        t_record = threading.Thread(target=t_record)
        t_record.setDaemon(True)
        t_record.start()

        record_time = threading.Thread(target=record_time)
        record_time.setDaemon(True)
        record_time.start()

        record_stop = threading.Thread(target=record_stop)
        record_stop.setDaemon(True)
        record_stop.start()

    def open_record_bind(s):
        def open_record():
            s.open_record_button_disable.place(x=20, y=370)
            screen_record.open_screenrecords()
            s.open_record_button_disable.place_forget()

        open_record = threading.Thread(target=open_record)
        open_record.setDaemon(True)
        open_record.start()

    def reset_bind(s):
        def t_reset():
            reset_message = languages_all['record_reset_content']
            if tkinter.messagebox.askyesno(title=languages_all['record_reset_title'], message=reset_message):
                screen_record.reset_screenrecord()
                tkinter.messagebox.showinfo(title=languages_all['complete'], message=languages_all['record_reset_success'])

        t_reset = threading.Thread(target=t_reset)
        t_reset.setDaemon(True)
        t_reset.start()

    def reset_disable_bind(s):
        tkinter.messagebox.showwarning(title=languages_all['record_warining_title'], message=languages_all['record_warining_doing'])

    def linux_button_bind(s):
        def t_linux_button():
            global adb_server_all_flag,linux_button_flag
            linux_button_flag = False

            def check_only_read():
                devices_SN = s.more_devices_value.get()
                check_only_read = public.execute_cmd('adb -s ' + devices_SN + ' shell ls -lh /data/.overlay')
                only_read = ' '.join(check_only_read.split()).split(':')[-1]
                return only_read

            while True:
                adb_model = open(adb_model_text, 'r').read()
                if not adb_server_all_flag or adb_model.strip() != 'linux':
                    linux_button_flag = False
                    print('已正常退出Linux模式，避免一直循环耗时！！！')
                    break
                else:
                    devices_finally = public.device_connect()
                    s.init_text = s.init_str.get()
                    only_read = check_only_read()
                    if not devices_linux_flag or not devices_finally or only_read.strip() == 'No such file or directory' \
                            or s.linux_type_str.get().strip() != languages_all['linux_firmware_quanzhi']:
                        if linux_button_flag:
                            # 断开Linux设备时关闭页面不释放按钮的禁用状态（也就是不显示对应的button）
                            with open(linux_button_flag_path,'w') as fp:
                                fp.write('')
                            s.linux_all_button_close()
                            linux_button_flag = False
                    elif devices_linux_flag and devices_finally and only_read.strip() != 'No such file or directory':
                        if s.linux_type_str.get().strip() == languages_all['linux_firmware_quanzhi']:
                            if not linux_button_flag:
                                # close值写错了，这个值无意义，只是标记成功连接Linux设备时关闭页面会释放按钮的禁用状态
                                with open(linux_button_flag_path, 'w') as fp:
                                    fp.write('close')
                                s.linux_all_button_open()
                                linux_button_flag = True
                    elif only_read.strip() == 'ls requires an argument':
                        error_content = languages_all['linux_error_content']
                        tkinter.messagebox.showerror(title=languages_all['linux_error_message'], message=error_content)
                        break
                time.sleep(3)

        s.t_linux_button = threading.Thread(target=t_linux_button)
        s.t_linux_button.setDaemon(True)
        s.t_linux_button.start()

    def linux_screen_bind(s):
        def t_screen():
            # 初始化页面
            with open(screen_page,'w') as fp:
                fp.write('0')
            linux_screen = linux_main.Linux_Screen()
            device_SN = s.more_devices_value.get()
            linux_screen.screen_form(s.init_str, s.linux_screen_Button, s.linux_screen_Button_disable, device_SN,
                                     s.adb_test_close_disable)

        t_screen = threading.Thread(target=t_screen)
        t_screen.setDaemon(True)
        t_screen.start()

    def linux_developer_mode_close_bind(s):
        def t_developer_mode_close():
            # 关闭开发者模式
            linux_developer_mode_content = languages_all['adb_mode_confirm']
            if tkinter.messagebox.askokcancel(title='', message=linux_developer_mode_content):
                s.init_str.set(languages_all['adb_mode_doing'])
                s.linux_developer_mode_Button_close.place_forget()
                s.linux_developer_mode_Button_close_disable.place(x=200, y=190)
                device_SN = s.more_devices_value.get()
                public.execute_cmd('adb -s ' + device_SN + ' shell rm -rf /data/.adb_config')
                public.execute_cmd('adb -s ' + device_SN + ' shell reboot')
                time.sleep(18)
                s.init_str.set(languages_all['adb_mode_success'])
            else:
                pass

        t_developer_mode_close = threading.Thread(target=t_developer_mode_close)
        t_developer_mode_close.setDaemon(True)
        t_developer_mode_close.start()

    def linux_install_bind(s):
        def t_install():
            # 初始化页面
            with open(install_page, 'w') as fp:
                fp.write('0')
            linux_install = linux_main.Linux_Install()
            device_SN = s.more_devices_value.get()
            linux_install.install_form(s.init_str, s.linux_install, s.linux_install_disable, device_SN,
                                       s.adb_test_close_disable)

        t_install = threading.Thread(target=t_install)
        t_install.setDaemon(True)
        t_install.start()

    @adb_tools_log
    def linux_camera_bind(s):
        def t_camera():
            # 初始化页面
            with open(camera_page, 'w') as fp:
                fp.write('0')
            linux_camera = linux_main.Linux_Camera()
            device_SN = s.more_devices_value.get()
            linux_camera.camera_form(s.init_str, s.linux_camera, s.linux_camera_disable, device_SN,
                                     s.adb_test_close_disable)

        t_camera = threading.Thread(target=t_camera)
        t_camera.setDaemon(True)
        t_camera.start()

    def uninstall_bind(s):
        def t_uninstall():
            global uninstall_flag
            # 卸载APK流程
            s.uninstall_button_disable.place(x=200, y=80)
            s.uninstall_str.set(languages_all['uninstall_apk_2'])
            # 卸载标记
            uninstall_flag = False
            s.check_package_name_bind(uninstall_flag)
            s.uninstall_button_disable.place_forget()

        t_uninstall = threading.Thread(target=t_uninstall)
        t_uninstall.setDaemon(True)
        t_uninstall.start()

    def check_package_name_bind(s, uninstall_flag):
        def t_check_package_name():
            global uninstall_flag
            # 检测当前包名
            s.check_package_name_button_disable.place(x=20, y=80)
            s.uninstall_button_disable.place(x=200, y=80)
            devices_state = public.device_connect()
            if not devices_state:
                s.uninstall_str.set(languages_all['uninstall_devices_null'])
                s.uninstall_label.unbind('<Button-1>')
            else:
                devices_sn = s.more_devices_value.get()
                device_type = public.device_type_android(devices_sn)
                if device_type.strip() == 'Android':
                    try:
                        s.uninstall_str.set(languages_all['found_package_doing'])
                        device_SN = s.more_devices_value.get()
                        package_name = public.found_packages(device_SN)
                        print('已检测到包名：{}'.format(package_name))
                        s.uninstall_str.set(languages_all['found_package_success'] + package_name)
                        s.uninstall_label.bind('<Button-1>', lambda x: public.pyperclip_copy_paste(package_name))

                        if not uninstall_flag:
                            s.uninstall_str.set(languages_all['found_package_home'] + package_name + languages_all['found_package_end'])
                            public.execute_cmd('adb -s ' + device_SN + ' uninstall ' + package_name)
                            uninstall_flag = True
                            s.uninstall_str.set(languages_all['uninstall_success'])
                        else:
                            pass
                    except (IndexError, TypeError):
                        s.uninstall_str.set(languages_all['record_type_error'])
                        s.uninstall_label.unbind('<Button-1>')
                else:
                    s.uninstall_str.set(languages_all['record_type_error'])
                    s.uninstall_label.unbind('<Button-1>')

            s.check_package_name_button_disable.place_forget()
            s.uninstall_button_disable.place_forget()

        t_check_package_name = threading.Thread(target=t_check_package_name)
        t_check_package_name.setDaemon(True)
        t_check_package_name.start()

    def write_number_bind(s):
        def t_write_number():
            # 初始化页面
            with open(write_number_page, 'w') as fp:
                fp.write('0')
            linux_write_number = linux_main.Linux_WriteNumber()
            device_SN = s.more_devices_value.get()
            linux_write_number.write_number_form(s.init_str, s.write_number, s.write_number_disable, device_SN,
                                                 s.adb_test_close_disable)

        t_write_number = threading.Thread(target=t_write_number)
        t_write_number.setDaemon(True)
        t_write_number.start()

    def uuid_main_bind(s):
        def t_uuid_main():
            # 手动获取UUID
            global uuid_run_flag
            # 恢复标识
            uuid_run_flag = True
            s.uuid_get_bind()
            return uuid_run_flag

        t_uuid_main = threading.Thread(target=t_uuid_main)
        t_uuid_main.setDaemon(True)
        t_uuid_main.start()

    def uuid_get_bind(s):
        def t_uuid_get():
            global uuid_reboot_flag, uuid_run_flag
            # 重新获取UUID
            s.uuid_get_disable.place(x=20, y=360)
            s.uuid_paste_disable.place(x=200, y=360)
            devices_state = public.device_connect()
            s.uuid_str.set(languages_all['linux_get_uuid_doing'])
            if not devices_state:
                s.uuid_str.set(languages_all['linux_uuid_devices_null'])
            else:
                # 直接获取UUID
                devices_sn = s.more_devices_value.get()
                uuid_get_result = public.execute_cmd('adb -s ' + devices_sn + ' shell ls -lh /data/UUID.ini')
                uuid_get_result_finally = ' '.join(uuid_get_result.split()).split(':')[-1]
                if uuid_get_result_finally.strip() == 'No such file or directory':
                    uuid = public.execute_cmd('adb -s ' + devices_sn + ' shell ag_os')
                    uuid_re = re.findall('uuid:(.*?)\\n', uuid)
                    uuid_result = ''.join(uuid_re).strip()
                    # 写入UUID后上传到设备中进行读取
                    with open(uuid_path, 'w') as fp:
                        fp.write(uuid_result)
                    public.execute_cmd('adb -s ' + devices_sn + ' push ' + uuid_path + ' /data/UUID.ini')
                    if uuid_result == '':
                        s.uuid_str.set(languages_all['linux_get_uuid_error'])
                        public.execute_cmd('adb -s ' + devices_sn + ' shell rm -rf /data/UUID.ini')
                    else:
                        s.uuid_str.set(languages_all['linux_get_uuid_success'] + uuid_result)
                else:
                    uuid_result = public.execute_cmd('adb -s ' + devices_sn + ' shell cat /data/UUID.ini').strip()
                    if uuid_result == '':
                        s.uuid_str.set(languages_all['linux_get_uuid_error'])
                        public.execute_cmd('adb -s ' + devices_sn + ' shell rm -rf /data/UUID.ini')
                    else:
                        # 需要判断当前设备的实际UUID，然后更新读取的UUID
                        uuid = public.execute_cmd('adb -s ' + devices_sn + ' shell ag_os')
                        uuid_re = re.findall('uuid:(.*?)\\n', uuid)
                        uuid_result_new = ''.join(uuid_re).strip()
                        if uuid_result != uuid_result_new:
                            with open(uuid_path, 'w') as fp:
                                fp.write(uuid_result_new)
                            # 重新上传到设备
                            public.execute_cmd('adb -s ' + devices_sn + ' push ' + uuid_path + ' /data/UUID.ini')
                            s.uuid_str.set(languages_all['linux_get_uuid_success'] + uuid_result_new)
                        else:
                            s.uuid_str.set(languages_all['linux_get_uuid_success'] + uuid_result)
            s.uuid_get_disable.place_forget()
            s.uuid_paste_disable.place_forget()

        t_uuid_get = threading.Thread(target=t_uuid_get)
        t_uuid_get.setDaemon(True)
        t_uuid_get.start()

    def uuid_paste_bind(s):
        def t_uuid_paste():
            # 一键复制UUID
            s.uuid_paste_disable.place(x=200, y=360)
            device_SN = s.more_devices_value.get()
            uuid_get_result = public.execute_cmd('adb -s ' + device_SN + ' shell ls -lh /data/UUID.ini')
            uuid_get_result_finally = ' '.join(uuid_get_result.split()).split(':')[-1]
            # agOsUUID_result = public.execute_cmd('adb -s ' + device_SN + ' shell ls -lh /data/agOsUUID.txt')
            # agOsUUID_result_finally = ' '.join(agOsUUID_result.split()).split(':')[-1]
            # and agOsUUID_result_finally.strip() == 'No such file or directory':
            if uuid_get_result_finally.strip() == 'No such file or directory':
                s.uuid_str.set(languages_all['linux_copy_uuid_error'])
            else:
                uuid_result = public.execute_cmd('adb -s ' + device_SN + ' shell cat /data/UUID.ini').strip()
                if uuid_result == '':
                    s.uuid_str.set(languages_all['linux_copy_uuid_error'])
                    public.execute_cmd('adb -s ' + device_SN + ' shell rm -rf /data/UUID.ini')
                else:
                    public.pyperclip_copy_paste(uuid_result)
 
            s.uuid_paste_disable.place_forget()

        t_uuid_paste = threading.Thread(target=t_uuid_paste)
        t_uuid_paste.setDaemon(True)
        t_uuid_paste.start()

    def get_log_bind(s):
        def t_get_log():
            # 初始化页面
            with open(get_log_page, 'w') as fp:
                fp.write('0')
            linux_get_log = linux_main.Linux_Log()
            device_SN = s.more_devices_value.get()
            linux_get_log.log_form(s.init_str, s.get_log, s.get_log_disable, device_SN, s.adb_test_close_disable)

        t_get_log = threading.Thread(target=t_get_log)
        t_get_log.setDaemon(True)
        t_get_log.start()

    def open_apk_path_files(s, apk_path_install_flag):
        def t_open_apk_path():
            # 打开库文件代码
            s.adb_test_close_disable.place(x=400, y=370)
            s.apk_path_package_button_disable.place(x=320, y=160)
            s.apk_path_button_disable.place(x=320, y=285)
            s.apk_path_package_entry.config(state='disable')
            s.apk_path_entry.config(state='disable')
            apkFilter = "APK Files (*.apk)|*.apk|"  # apk文件过滤
            # apk_path_file = tkinter.filedialog.askopenfile(mode='r', filetypes=[('Apk Files', '*.apk')], title='选择apk安装文件')
            # apk_path_file_string = str(apk_path_file)
            dlg = win32ui.CreateFileDialog(True, "csv", None, 0x04 | 0x02, apkFilter)  # True表示打开文件对话框，0或False表示另存为对话框
            path_msg = open(apk_path_package_log, 'r').read()
            if not apk_path_install_flag:
                path_msg_finally = '\\'.join(path_msg.split('\\')[:-1])  # 只获取目录地址（不包含具体文件）
                dlg.SetOFNInitialDir(path_msg_finally)  # 设置打开文件对话框中的初始显示目录
            else:
                apk_path = open(apk_path_log, 'r').read()
                apk_path_finally = '\\'.join(apk_path.split('\\')[:-1])
                dlg.SetOFNInitialDir(apk_path_finally)
            dlg.DoModal()  # 显示文件选择框
            apk_path_file = dlg.GetPathName()  # 获取选择的文件名称
            print('apk安装标识：' + str(apk_path_install_flag))
            if apk_path_file == '':
                if apk_path_install_flag:
                    s.install_str.set(languages_all['select_apk_null'])
                else:
                    s.uninstall_str.set(languages_all['select_apk_null'])
            else:
                # replace('/','\\')替换路径符号，提高最准确无误的文件绝对路径
                # print('apk路径获取源数据：' + apk_path_file_string)
                # apk_path_file_finally = eval(apk_path_file_string.split()[1].split('=')[1]).replace('/','\\')
                # 更换为 re正则表达式 判断
                # apk_path_file_finally = ''.join(re.findall('name=\'(.*?)\'\s', apk_path_file_string)).replace('/', '\\')
                if apk_path_install_flag:
                    s.apk_path_str.set(apk_path_file)
                    print('获取地址：' + str(apk_path_file))
                    with open(apk_path_log, 'w') as fp:
                        fp.write(apk_path_file)
                    fp.close()
                else:
                    s.apk_path_package_str.set(apk_path_file)
                    print('获取地址：' + str(apk_path_file))
                    with open(apk_path_package_log, 'w') as fp:
                        fp.write(apk_path_file)
                    fp.close()
            s.apk_path_package_entry.config(state='normal')
            s.apk_path_entry.config(state='normal')
            s.apk_path_button_disable.place_forget()
            s.apk_path_package_button_disable.place_forget()
            s.adb_test_close_disable.place_forget()

        t_open_apk_path = threading.Thread(target=t_open_apk_path)
        t_open_apk_path.setDaemon(True)
        t_open_apk_path.start()

    @adb_tools_log
    def apk_package_bind(s):
        def t_apk_package():
            # 根据apk文件获取包名
            s.apk_package_button_disable.place(x=20, y=200)
            s.uninstall_str.set(languages_all['found_apk_package_doing'])
            s.apk_path_package_get = s.apk_path_package_str.get()
            print(s.apk_path_package_get)
            apk_package_cmd = 'aapt dump badging ' + '"' + s.apk_path_package_get + '"' + ' > ' + apk_aapt_log
            apk_package_result = public.execute_cmd(apk_package_cmd)
            try:
                apk_package_result_error = apk_package_result.split(' ')[1].split('\n')[0].strip()
                if apk_package_result_error == '不是内部或外部命令，也不是可运行的程序':
                    s.uninstall_str.set(languages_all['found_aapt_null'])
                    s.adb_str.set(languages_all['adb_upgrade_doing_now'])
                    with open(adb_upgrade_flag, 'w') as fp:
                        fp.write('ADB upgrade')
                    fp.close()
                    public.upgrade_adb()
                    with open(adb_upgrade_flag, 'w') as fp:
                        fp.write('')
                    fp.close()
                    s.uninstall_str.set(languages_all['adb_upgrade_success_now'])
                    s.adb_str.set(languages_all['adb_configuration_finally'])
            except IndexError:
                pass
            # errors='ignore' 忽略错误，避免个别计算机出现异常
            apk_package_result_log = open(apk_aapt_log, 'r', encoding='utf-8', errors='ignore').read()
            # print(apk_package_result_log)
            apk_package_result_finally = ''.join(re.findall('package: name=\'(.*?)\'\s', apk_package_result_log))
            # print(apk_package_result_finally)
            apk_version_result_finally = ''.join(re.findall('versionName=\'(.*?)\'\s', apk_package_result_log))
            # print(apk_version_result_finally)
            apk_name_result_finally = ''.join(re.findall('application-label-zh:\'(.*?)\'\s', apk_package_result_log))
            # print(apk_name_result_finally)
            if apk_name_result_finally.strip() == '':
                apk_name_result_finally = ''.join(
                    re.findall('application-label-en:\'(.*?)\'\s', apk_package_result_log))
            if apk_package_result_finally == '' and apk_version_result_finally == '' and apk_name_result_finally == '':
                s.uninstall_str.set(languages_all['select_not_apk'])
            else:
                apk_size_result = os.stat(s.apk_path_package_get).st_size
                # print(apk_size_result)
                apk_size = round(apk_size_result / 1024 / 1024, 2)
                # print(apk_size)
                apk_md5 = public.file_md5(s.apk_path_package_get)
                print(languages_all['get_all_apk_info'] + apk_package_result_finally
                      + languages_all['get_all_apk_name'] + apk_name_result_finally + languages_all['get_all_apk_version'] + apk_version_result_finally +
                      languages_all['get_all_apk_size'] + str(apk_size_result) + ' byte (' + str(apk_size) + 'MB)' +
                      languages_all['get_all_apk_md5'] + apk_md5)
                print('---------------------------------------------')
                with open(apk_aapt_log, 'w') as fp:
                    if fp is not None:
                        fp.write(languages_all['get_all_apk_info'] + apk_package_result_finally
                      + languages_all['get_all_apk_name'] + apk_name_result_finally + languages_all['get_all_apk_version'] + apk_version_result_finally +
                      languages_all['get_all_apk_size'] + str(apk_size_result) + ' byte (' + str(apk_size) + 'MB)' +
                      languages_all['get_all_apk_md5'] + apk_md5)
                fp.close()
                s.uninstall_str.set(languages_all['get_all_apk_copy_info'])
            s.apk_package_button_disable.place_forget()

        t_apk_package = threading.Thread(target=t_apk_package)
        t_apk_package.setDaemon(True)
        t_apk_package.start()

    def apk_package_copy_bind(s):
        def t_apk_package_copy():
            s.apk_package_copy_button_disable.place(x=200, y=200)
            apk_info_name = open(apk_aapt_log, 'r').read()
            if apk_info_name == '':
                tkinter.messagebox.showinfo(languages_all['null_packages'], languages_all['get_null_apk_info'])
            else:
                public.pyperclip_copy_paste(apk_info_name)
            s.apk_package_copy_button_disable.place_forget()

        t_apk_package_copy = threading.Thread(target=t_apk_package_copy)
        t_apk_package_copy.setDaemon(True)
        t_apk_package_copy.start()

    def apk_path_insatll_bind(s):
        # 选择apk文件逻辑
        global apk_path_install_flag
        apk_path_install_flag = True
        s.open_apk_path_files(apk_path_install_flag)
        apk_path_install_flag = False

    def apk_install_bind(s):
        def t_apk_install():
            # 安装apk逻辑
            global apk_install_flag
            s.apk_button_disable.place(x=20, y=325)
            s.apk_install_info_button_disable.place(x=200, y=325)
            apk_install_flag = True
            devices_state = public.device_connect()
            if not devices_state:
                s.install_str.set(languages_all['install_devices_null'])
            else:
                devices = s.more_devices_value.get()
                device_type = public.device_type_android(devices)
                if device_type.strip() == 'Android':
                    s.install_str.set(languages_all['install_apk_doing'])
                    apk_path = s.apk_path_str.get()
                    apk_install_options = s.apk_install_mode_value.get()
                    if apk_install_options == languages_all['install_mode_default']:
                        apk_install_model = ''
                    elif apk_install_options == languages_all['install_mode_d']:
                        apk_install_model = '-d '
                    apk_install_cmd = 'adb -s ' + devices + ' install -r ' + apk_install_model + '"' + apk_path + '"'
                    print('安装命令显示：' + apk_install_cmd)
                    install_result = public.execute_cmd(apk_install_cmd)
                    # install_result = public.linux_sn_cmd(apk_install_cmd)
                    print('安装结果：' + install_result)
                    if 'Success' not in install_result:
                        s.install_str.set(languages_all['install_apk_fail_info'])
                        if install_result.strip() == '':
                            with open(apk_install_log, 'w') as fp:
                                fp.write(languages_all['install_apk_fail_content'])
                        else:
                            with open(apk_install_log, 'w') as fp:
                                fp.write(install_result)
                        fp.close()
                        apk_install_flag = False
                        s.apk_button_disable.place_forget()
                        s.apk_install_info_button_disable.place_forget()
                        # return 直接从此处跳出，不执行下方代码
                        return
                    try:
                        install_error = install_result.split(' ')[1]
                        if install_error.strip() == 'failed':
                            s.install_str.set(languages_all['install_apk_fail_info'])
                            if install_result.strip() == '':
                                with open(apk_install_log, 'w') as fp:
                                    fp.write(languages_all['install_apk_fail_content'])
                            else:
                                with open(apk_install_log, 'w') as fp:
                                    fp.write(install_result)
                            fp.close()
                            apk_install_flag = False
                            s.apk_button_disable.place_forget()
                            s.apk_install_info_button_disable.place_forget()
                            # return 直接从此处跳出，不执行下方代码
                            return
                    except IndexError:
                        pass

                    with open(apk_install_log, 'w',encoding='utf-8') as fp:
                        fp.write(install_result)
                    fp.close()
                    print('安装结果：' + install_result)
                    s.install_str.set(languages_all['install_apk_success'])
                else:
                    s.install_str.set(languages_all['install_apk_not_android'])
            apk_install_flag = False
            s.apk_button_disable.place_forget()
            s.apk_install_info_button_disable.place_forget()

        t_apk_install = threading.Thread(target=t_apk_install)
        t_apk_install.setDaemon(True)
        t_apk_install.start()

    def apk_install_info_bind(s):
        def t_apk_install_info():
            # 查看apk安装信息
            s.apk_install_info_button_disable.place(x=200, y=325)
            if not os.path.exists(apk_install_log):
                with open(apk_install_log, 'w') as fp:
                    fp.write('')
                fp.close()
            win32api.ShellExecute(0, 'open', apk_install_log, '', '', 1)
            s.apk_install_info_button_disable.place_forget()

        t_apk_install_info = threading.Thread(target=t_apk_install_info)
        t_apk_install_info.setDaemon(True)
        t_apk_install_info.start()

    def flow_bind(s):
        def t_flow():
            devices_state = public.device_connect()
            if not devices_state:
                content = languages_all['flow_devices_null_content']
                tkinter.messagebox.showerror(title=languages_all['flow_devices_null'], message=content)
            else:
                flow = customize_main.Flow_Screen()
                flow.flow_form(s.flow_button, s.flow_button_disable, s.adb_test_close_disable,page_state_list)

        t_flow = threading.Thread(target=t_flow)
        t_flow.setDaemon(True)
        t_flow.start()

    def md5_size_bind(s):
        def t_md5_size():
            md5_size = customize_main.MD5_Screen()
            s.md5_size_button.place_forget()
            s.md5_size_button_disable.place(x=200, y=20)
            s.adb_test_close_disable.place(x=400, y=370)
            md5_size.md5_size_form(s.md5_size_button, s.md5_size_button_disable, s.adb_test_close_disable,page_state_list,\
                                   s.adb_test_close)

        t_md5_size = threading.Thread(target=t_md5_size)
        t_md5_size.setDaemon(True)
        t_md5_size.start()

    def linux_extra_bind(s):
        def t_linux_extra():
            # 初始化页面
            with open(public.linux_extra_page(), 'w') as fp:
                fp.write('0')
            linux_extra = linux_main.Linux_Quick()
            device_SN = s.more_devices_value.get()
            linux_extra.quick_form(s.init_str, s.linux_extra_Button, s.linux_extra_Button_disable, device_SN,
                                   s.adb_test_close_disable)

        t_linux_extra = threading.Thread(target=t_linux_extra)
        t_linux_extra.setDaemon(True)
        t_linux_extra.start()

    def linux_debug(s):
        def t_linux_debug():
            # 快速调试模式
            device_SN = s.more_devices_value.get()
            linux_main.linux_debug_bind(device_SN)

        t_linux_debug = threading.Thread(target=t_linux_debug)
        t_linux_debug.setDaemon(True)
        t_linux_debug.start()
